Tuesday, January 29, 2013

WEB FORM VALIDATION USING JAVA SCRIPT

                        WEB FORM VALIDATION USING JAVA SCRIPT

AIM:
          To implement Client Side Scripts for validating Web form Controls using DHTML.
ALGORITHM:
Step1: Start the program.
Step2: Include all the information using forms.
Step 3: Validate the forms by checking conditions.
Step 4: If the given input is not matched then the validation is done and a error message is displayed.
Step 5:Stop the program.
CODING:
FormValidation.html
<html>
<head>
<title>Form Validation Using Java Script</title>
<script type="text/javascript">
function validation()
{
 if(document.frm.txt.value=="")
 {
  window.alert("Plz Enter the E-mail");
 }
 else if(document.frm.txt.value.indexOf('@')==-1)
 {
  window.alert("Invalid User Name");
 }
 else if(document.frm.pass.value=="")
 {
  window.alert("Plz Enter the Password");
 }
 else if(document.frm.txt1.value=="")
 {
  window.alert("Plz Enter Your Name");
 }
 else if(document.frm.addr.value=="")
 {
  window.alert("Plz Enter Your Address");
 }
 else if((document.frm.rdo[0].checked==false)&&(document.frm.rdo[1].checked==false))
 {
  window.alert("Plz Choose Your Gender");
 }
 else if(document.frm.age.selectedIndex==0)
 {
  window.alert("Plz Choose Your Age");
 }
 else if(document.frm.chk.checked==false)
 {
  window.alert("Plz Agree The Terms And Conditions");
 }
 else
 document.location="Register.html";
}
</script>
</head>
<body>
<form name="frm">
<label>
Enter Your E-mail:<input type="text" name="txt">
</label><br><br>
<label>
Enter Password:&nbsp;&nbsp;&nbsp;<input type="password" name="pass">
</label><br><br>
<label>
Enter Your Name:<input type="text" name="txt1">
</label><br><br>
Address:<br>
<Textarea name="addr" rows="5" cols="20">
</Textarea><br><br>
<label>
Gender:
<input type="radio" name="rdo">Male
<input type="radio" name="rdo">Female
</label><br><br>
Age:
<select name="age">
<option>---Select Your Age---</option>
<option>21</option>
<option>22</option>
<option>23</option>
</select>
<br><br>
<input type="checkbox" name="chk">I Agree
<input type="button" value="Register Me" onclick="validation()">
</form>
</body>
</html>
Register.html
<html>
<head>
<title>Registration Successfull</title>
</head>
<body>
<h3>Registered Successfully.......!</h3>
</body>
</html>

RESULT:
                    Thus the web form validation using JavaScript is executed and output is verified.

No comments:

Post a Comment

Leave the comments