Wednesday, February 22, 2012

PHP JavaScript form validation



This program for validation checking using JavaScript . Copy and paste the program ,It will check whether the form is filled correctly or not. Java script is client side scripting language and generally used for form validation . By the time of form submission onsubmit event will occur and it will check form object.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript">
function abc()
{
       var name=document.getElementById("name").value;
       var age=document.getElementById("pass").value;
       if(name=="" || age=="")
       {
         alert("Enter name and age");
       }
}

</script>
</head>

<body>
<form name="myform" method="post" onSubmit="abc()">
Enter name:-<input type="text" id="name">
Password:  <input type="password" id="pass">
<input type="submit" value="Submit me">
</form>
</body>
</html>

No comments:

Post a Comment