Javascript Form Validation

JavaScript Form Validation:
The form validation will usually take place at server and this happens after entry of all needed data and then the submit button is processed.
If data that the client enters is missing or incorrect, the server has to send back all data to client and must request for form resubmission.
This is a very long process that gives lots of workload for server.
JavaScript will provide the way for validating the data of the form on client’s system before sending the data to web server.

There are two functions performed by form validation:
•    Basic Form Validation– To begin, you must check the form and make sure that all important fields are filled up. This will need just loops along every field and data check for each data.
•    Format of Data Validation– Next, the entered data should be checked for proper value and form. The code you entered should consist of proper logic for testing the correctness of the data value.

Example:
Let us consider the below example for understanding the validation process.
Listed below is a simple HTML format:

<html>
<head>
<title>Form Validation using JavaScript</title>

<script type="text/javascript">
<!--
            // The code for Form validation
         //-->
</script>
</head>
<body>
<form action="/cgi-bin/test.cgi" name="sampleForm" onsubmit="return(validate());">
<table cellspacing="3" cellpadding="3" border="1.5">
<tr>
<td align="left">FirstName</td>
<td><input type="text" name="FirstName" /></td>
</tr>
<tr>
<td align="left">mailid</td>
<td><input type="text" name="mailid" /></td>
</tr>
<tr>
<td align="left">Country Code</td>
<td><input type="text" name="Country Code" /></td>
</tr>
<tr>
<td align="left">Location</td>
<td>
<select name="Location">
<option value="0" selected></option>
<option value="1">Bangladesh</option>
<option value="2">Indonesia</option>
<option value="3">China</option>
</select>
</td>
</tr>
<tr>
<td align="left"></td>
<td><input type="Button" value="Submit" /></td>
</tr>
</table>
</form>
</body>
</html>