Click to See Complete Forum and Search --> : Form Validation for every field before submit


shanuragu
06-04-2003, 02:31 AM
HI

How to validate form fields before submit ie, the when I goto the next field the previous validation should fire(if any). I am trying to do this with onblur, but it fires the validate function when the cursor focus on that field. Please help me to solve this problem. Urgent please.

ShaRa:confused:

Gollum
06-04-2003, 02:49 AM
The onblur should do it...

<input type=text onblur="if ( !valid(this.value) this.focus();">

difficult to say more without seeing your code

shanuragu
06-04-2003, 04:23 AM
HI

thanks for ur reply,
Here is the sample code for one form field
<script language="javascript">
function Validate()
{
if (isEmpty(document.form.text1.value))
{
document.form.text1.focus();
return false;
}
}

</script>
<form name='form' method='post'>
<table>
<tr>
<td>
<input type='text' name='text1' onblur="validate()">
</td>
</tr>
</table>
</form>

isEmpty is javascript function(in ajs folder & is linked), is as follows
function isEmpty(strValue) {
if(strValue=="") {
alert("This field must NOT be empty.");
return true;
}

return isSpaces(strValue);
}

please reply.
ShaRa