View Full Version : JS Form validation

11-19-2011, 12:26 AM
I want to create a javascript form validation but i cant validate with the following code.
What is wrong with the code? How to create a form validation without much modification of the following code-

<head><title>Javascript Validation</title>
left: 30px;
float right;
function validate()
var c=document.getElementById("f1").value;
alert(" Name Field can't be blank");
alert("Enter a valid name");
var a=parseInt(document.getElementById("f6").value);alert(a);
var b=document.getElementById("f7").value;alert(b);
var d=document.getElementById("f8").value;alert(d);
var lp=0;
if((d%400)==0 && (d%100==0) || (d%4==0))
if((a==31) && ((b=="4") || (b=="6") || (b=="9") || (b=="11")) )
alert("Date out of Range");
if((lp==0) && ((a=="29") || (b=="2") )
alert("Date out of Range");
<div style="width:50%;background-color:lightgray;">
<legend style="color:brown;font-weight:bold;"> SignUp Form</legend>
<table height=300>
<tr><td> FirstName:&nbsp;&nbsp;<input type="text" name="fn" id="f1" class="lf" size=50 /></td></tr>
<tr><td> Address: &nbsp;&nbsp;&nbsp; <input type="text" name="adr" id="f2" class="lf" size=50 /></td></tr><br/><br/>
<tr><td> Zip:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="zp" id="f3" class="lf" size=20 /></td></tr><br/><br/>
<tr><td> UserName:&nbsp;<input type="text" name="fn" id="f4" class="lf" size=30 /></td></tr>
<tr><td> Password: &nbsp;&nbsp;<input type="password" name="fn" id="f5" class="lf" size=30 /></td></tr>
<tr><td> DOB: <br /><br />Day:&nbsp;&nbsp;&nbsp;<input type="text" name="dy" id="f6" />
Month:&nbsp;<input type="text" name="m1" id="f7" />
Year:&nbsp;<input type="text" name="m2" id="f8" /></td></tr>
<tr><td> Email:&nbsp;&nbsp;
<input type="text" name="fn" id="f9" size=50 /></td></tr>
<input type="submit" value="submit" onClick="validate()" />