SQL PHP HTML ASP JavaScript articles and free scripts to download If you are facing any problem in viewing this page, please tell us
 

Javascript Form Validation


We can validate the entry of any form by using JavaScript. This is a client side JavaScript form validation and you can check server side php form validation also. Before taking up any client side validation it is advisable to check JavaScript is not disabled in the client browser.


You can see a demo of Form Validation here.




Notice how you are prevented from submitting form unless the text input field is filled.


Input :


Here is the sample source code of the above demo

<html>
<head>
<title>Javascript Form Validation</title>
<script language='JavaScript' type='text/JavaScript'>
<!--
function validate() {
	if(document.form1.textinput.value=='')
		{
		alert('Fill the Input box before submitting');
		return false;
		}
	
	else	{
		return true;
			}
}
//-->
</script>
</head>
<body>
<form name='form1' action='javascript_validation.php' method='post' 
				onSubmit='return validate();'>
Input :<input type=text name=textinput value=''>
<input type=submit value=submit>
</form>
</body>
</html>

Further readings
Disabling the submit button till all the elements of the form are validated
getElementById to access form elements with event handlers
Javascript Form Validation
Period button Validation of a form
How to limit number of checkboxes allowed to be clicked inside a form
Checkbox Validation of a form
Displaying checked value of a check box array
Enable or disable of a text box by a checkbox
All Checking & Un checking in a group of checkboxes by single button
Adding options to a drop down list box
Removing options from a drop down list box
Moving options from one drop down list box to other
Dynamic population of second list box based on value of first list box
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
Form validation
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.