Once the client or user entered all the necessary data and press the submit button then all the data entered by the client must be correct and valid. Thus, form validation is the mechanism which allows client to enter only the correct information which can be send to the server. JavaScript provides easy method for form validation at client side. Forma validation 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>
<HEAD><TITLE>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("Please!! Fill up the form");
}
}
</SCRIPT>
</BODY>
</HTML>
Click here for Adding two number in JavaScript.