This is a Small but very useful JavaScript form/fields validation with focus The Javascript add the code below before your “head” closing tag
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<script type="text/javascript">// <![CDATA[
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value==”")
{
alert(alerttxt);return false;
}
else
{
return true;
}
}
}
function validate_form(thisform)
{
with (thisform)
{
if (validate_required(posEmail,”Email must be filled out!”)==false)
{Email.focus();return false;}
if (validate_required(posText,”Message must be filled out!”)==false)
{Name.focus();return false;}
if (validate_required(posName,”Name must be filled out!”)==false)
{Message.focus();return false;}
}
}
// ]]></script> |
The form Add This to your form
|
1 |
onsubmit="return validate_form(this) |
So it Looks Like This Name: Email: Message: