Saturday 29 December 2012

CLIENT SIDE SCRIPTS FOR VALIDATING USING DHTML

<html>
<head>
<title>Admission</title>
<script Language="JavaScript">
function validat()
{
var un=document.f.t1.value;
var n=un.length;
var pw1=document.f.p1.value;
var pw2=document.f.p2.value;
var mid1=document.f.t2.value;
var n1=mid1.length;
var mid2=document.f.t3.value;
var sex=document.f.g1.value;
var dat1=document.f.s1.value;
var dat2=document.f.s2.value;
var dat3=document.f.s3.value;
var cond=document.f.c1.value;
if(!un)
{
alert("Please enter User Name");
return false
}
else
{
for(var i=0;i<n;i++)
{
var x=un.charAt(i)
if(x>='0'&&x<='9')
{
alert("Invalid Name.. Enter only Text");
return false
}}}
if(!pw1)
{
alert("Please enter Password");
return false
}
if(!pw2)
{
alert("Please Confirm ur Password");
return false
}
else if(pw1==pw2)
{}
else
{
alert("Invalid Password.. Enter Again");
return false
}
if(!mid1)
{
alert("Please enter Mail ID");
return false
}
else
{
for(var i=0;i<n1;i++)
{
var x1=mid1.charAt(i)
if(x1=='@')
{
var c=true;
break;
}}
if(c==false)
{
alert("Please enter Correct Mail ID");
return false
}}
if(!mid2)
{
alert("Please Confirm ur Mail ID");
return false
}
else if(mid1==mid2)
{}else{
alert("Invalid Mail ID.. Please enter Again");
return false
}
if(sex==false)
{
alert("Please select Sex");
return false
}
if(dat1!=false)
{
alert("Please select Date");
return false
}
else if(dat2!=false)
{
alert("Please select Month");
return false
}
else if(dat3!=false)
{
alert("Please select Year");
return false
}
if(!cond)
{
alert("Please Agree to the Conditions and try again");
return false
}
else if(confirm("Form filled Successfully..Click ok to enter into ur home page"))
{
window.open("main1.html");
return true
}
}
function clear()
{
document.f.t1.value=" ";
document.f.p1.value=" ";
document.f.p2.value=" ";
document.f.t2.value=" ";
document.f.t3.value=" ";
document.f.g1.value=false;
document.f.s1.value=false;
document.f.s2.value=false;
document.f.s3.value=false;
document.f.c1.value=false;
}
</script>
<br>
<center>
<h4>Registration Form</h4>
</center>
</head>
<body background="r3.jpg" text="#000080">
<form name="f" >
<font size=5>
<table cellspacing=10 cellpadding=10>
<tr><th><i><b><h3>User Name<td><input type="text" name="t1" size=50/>
<tr><th><i><b><h3>Password<td><input type="password" name="p1" size=50/>
<tr><th><i><b><h3>Confirm Password<td><input type="password" name="p2" size=50/>
<tr><th><i><b><h3>E-Mail ID<td><input type="text" name="t2" size=50/>
<tr><th><i><b><h3>Confirm E- Mail ID<td><input type="text" name="t3" size=50/>
<tr><th><i><b><h3>Sex<td><input type="radio" name="g1" /><i>Male&nbsp;&nbsp;
<input type="radio" name="g1"/><i>Female<tr><th><i><b><h3>Date<td>
<select name="s1"/>
<option>1<option>2<option>3<option>4<option>5<option>6<option>7<option>8<option>9<option>10<option>11<option>12<option>13<option>14<option>15<option>16<option>17<option>18<option>19<option>20<option>21<option>22<option>23<option>24<option>25<option>26<option>27<option>28<option>29<option>30<option>31<tr><th><i><b><h3>Month<td>
<select name="s2"/>       
<option>Jan<option>Feb<option>Mar<option>Apr<option>May<option>Jun<option>Jul<option>Aug<option>Sep<option>Oct<option>Nov<option>Dec
<tr><th><i><b><h3>Year<td>
<select name="s3"/>
<option>2005<option>2006<option>2007<option>2008<option>2009<option>2010<option>2011<option>2012<option>2013<option>2014<option>2015<option>2016
<tr><th><i><b><h3><input type="checkbox" name="c1" />I agree to the terms and Conditions
</table><br></font>
<center><input type="image"  src="reg.gif" value="Register" height="50" width="110" border="1" onClick="validat()"/>
&nbsp;&nbsp;
<input type="image” src="res.gif" value="Clear" height="50" width="110" border="1" onClick="clear()">
</form>
</body>
</html>

No comments:

Post a Comment