LEARNING FORM VALIDATION IN JS
Form validation is the mechanism which allows the client to enter only the correct information which can be sent to the server. JavaScript provides an easy method for form validation at the client side. It can be done in two ways: Basic validation which checks whether all the required fields are filled properly or not kept empty whereas, Data Format validation check whether the data entered into the form field are logically correct.
<HTML>
Example of form validation:
<HEAD>
<TITLE>Example of form validation</TITLE>
</HEAD>
<BODY>
<FORM>
<INPUT type = "text" id = "user">
<INPUT type = "password" id = "pass">
<INPUT type = "submit" onclick = "valid( )">
</FORM>
<SCRIPT>
function valid()
{
var user = document.getElementById("user").value;
var pass = document.getElementById("pass").value;
if(user == "" || pass == "")
{
alert(" Fill up the form");
}
}
</SCRIPT>
</BODY>
</HTML>
Comments
Post a Comment