HTML form validation can be done by a JavaScript,HTML and PHP.
This tutorial show the validation in Javascript.If a form field is empty, this function alerts a message, and returns false, to prevent the form from being submitted:
1 2 3 4 5 6 7 8 9 10 11 12 13 | <form onsubmit="return validation();">
<table>
<tr>
<td>Name:</td>
<td><input type="" name="fname" id="fname"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="Password" name="pass" id="pass"></td>
</tr>
</table>
</form>
|
In above form a function validation run on form submit and the in Javascript get the value by id and if the field is null it give the error in form of alert box.here is the javascript code for the validation.
1 2 3 4 5 6 7 8 9 10 11 12 13 | function validation()
{
if(document.getElementById("fname").value== '')
{
alert("Please Enter Name");
return false;
}
if(document.getElementById("pass").value== '')
{
alert("Please Enter Password");
return false;
}
}
|
In the Javascript get value from the id and if the value is null then it give the alert box.
and main thing is that the function name must be same in both side.
Sign up here with your email

ConversionConversion EmoticonEmoticon