Validation of Text field not working

vasy

New Member
I have html page with checkboxes and text fields and the JavaScript is able to validate the checkboxes but not the textfields. Can someone help as I am not sure where it is wrong \[code\]<html> <head> <script type="text/javascript"> function validator() { var c = document.getElementsByName("chk"); var k=false; for( var i=0; i<c.length; i++ ) { if( c.checked ) { k=true; return(true); } } if(k){ return(true); } else{ alert("Select one environment"); return(false); } var ap = form.getElementById("a1"); if(ap.value =http://stackoverflow.com/questions/15858364/="" || ap.length == 0) { alert("Enter the path"); ap.setfocus(); return(false); } else { return(true); } var p = form.getElementById("a2"); if(p.value =http://stackoverflow.com/questions/15858364/="" || p.length == 0) { alert("Enter the path"); form.p.setfocus(); return(false); } return(true); } </script> </head> <body> <form action="/car.java" onsubmit="return validator(this);"> <br /> <p> <input name="chk" type="checkbox" />One <input name="chk" type="checkbox" />Two <input name="chk" type="checkbox" />Three </p> <br /> <input name="a1" id="a1" size="123" style="width: 766px; height: 21px;" type="text" /> </p> <p> <input name="a2" id="a2" size="123" style="width: 766px; height: 21px;" type="text" /> </p> <textarea cols="95" name="status" rows="11"></textarea> <input name="sub" size="28" style="width: 156px; height: 29px;" type="button" value="http://stackoverflow.com/questions/15858364/Submit" /> </p> </form> </body> </html>\[/code\]
 
Top