javascript - JS Form validation is not working For html form -
i have simple html form. form follows-
<table> <form method="post" action="insert.php" name="idea_1" id="idea_1" onsubmit="return idea_1_check();" > <input type="hidden" name="type" value="idea" /> <tr><td></td><td><br><h3 style="color:#990066; font-weight:bold;">first member (team leader)</h3><br></td></tr> <tr><td></td><td><input type="text" name="stu_name_1" value="" placeholder="your full name"></td></tr> <input type="text" name="school_name_1" value="" placeholder="your school name"></td></tr> <tr><td></td><td><input type="text" name="stu_id_1" value="" placeholder="your student id/roll"></td></tr> <tr><td></td><td> <select name="class_1" id="class" required > <option selected="selected" value="">please select class</option> <option value="six">six</option> <option value="seven">seven</option> <option value="eight">eight</option> <option value="nine">nine</option> <option value="ten">ten</option> </select> </td></tr> </td><td> <select name="division_1" id="division" required> <option selected="selected" value="">please select division</option> <option value="dhaka">dhaka</option> <option value="chittagong">chittagong</option> <option value="sylhet">sylhet</option> </select> </td></tr> <tr><td></td><td><input type="text" name="mobile_1" value="" placeholder="your parent's mobile" required id="phone" ></td></tr> <tr><td></td><td><input type="text" name="interest_1" value="" placeholder="your interest e.g.: robotics, physics, chemistry, biology "></td></tr> <tr><td></td><td><textarea name="address_1" required id="must"="required id="must"" placeholder="your full residential address"></textarea></td></tr> <tr><td></td><td><input type="text" name="email_1" value="" placeholder="your email address" id="email_1" ><img id="tick_1" src="tick.png" width="16" height="16"/> <img id="cross_1" src="cross.png" width="16" height="16"/></td></tr> </table> <br> <p class="submit"><input type="submit" name="commit" value="register" ></p><br> <label> <div align="center"><a href="http://ignite-bd.com/submit-concept-paper/" target="_blank"><strong>upload concept paper within 3 weeks (21 days) qualify divisional round</strong> </a> </div> </label> <br><br> </form>
and javascript validation function follows:
function idea_1_check() { var stu_name=document.forms["idea_1"]["stu_name_1"].value; var school=document.forms["idea_1"]["school_name_1"].value; var id=document.forms["idea_1"]["stu_id_1"].value; var mob=document.forms["idea_1"]["mobile_1"].value; var add=document.forms["idea_1"]["address_1"].value; var email=document.forms["idea_1"]["email_1"].value; var atpos=email.indexof("@"); var dotpos=email.lastindexof("."); if (stu_name==null || stu_name=="" || stu_name.length<6) { alert("please provide full name"); return false; } if (school==null || school=="" || school.length<6) { alert("please provide full school name"); return false; } if (id==null || id=="" || id.length<1) { alert("please provide roll/id"); return false; } if (add=null || add=="" || add.length<10) { alert("please provide full residential address"); return false; } else if (email==null || email=="") { alert("email must filled out."); return false; } else if (atpos <1 || dotpos <atpos+2 || dotpos + 2 >= email.length) { alert("not valid e-mail address"); return false; } }
everything looks fine. validation not working. same code similar working. problem code?
just add return true
@ end of validate function, form submit if there no validation errors
Comments
Post a Comment