im using java script for form validation..
here is the code
The script working fine with email validation and also the last one function is for contact no input field only takes numbers every thing is working fi9 now i want the code to work like if name field is empty it says fill name and so on for all input fields.
HTML FORM:
here is the code
Code:
<script type="text/JavaScript">
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(email,"Email must be filled out!")==false)
{email.focus();return false;}
}
}
function valid(f) {
if (!/^\d*$/.test(f.value)) {
alert("Only integer numbers allowed!");
f.value = f.value.replace(/[^\d]/g,"");
}
}
</script>
The script working fine with email validation and also the last one function is for contact no input field only takes numbers every thing is working fi9 now i want the code to work like if name field is empty it says fill name and so on for all input fields.
HTML FORM:
Code:
div id="forminfo"><form name="theform" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validate_form(this)" method="POST">
First Name:
*************<INPUT type="text" name=fname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Last Name:
*************<INPUT type="text" name=lastname style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Email Address:*******<INPUT type="text" name=email style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Address:
******************<INPUT type="text" name=address style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
City:
**************************<INPUT type="text" name=city style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Province:
*****************<INPUT type="text" name=province style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
Contact No:
************<INPUT type="text" name=contactno maxlength="11" onkeyup="valid(this)" style="HEIGHT: 19px; WIDTH: 174px" size="20" align="center">
<br>
<br>
<br>
***********************************************************************************<input type="submit" name="submit" value="submit" />
</form>
Comment