javascript - JS Form Validation not working for simple html form -
i have simple html form 1 filed. form follows-
<table> <form action="insert.php" method="post" name="discover" onsubmit="return discover()"> <tr><td></td><td><input type="text" name="name"></td></tr> <tr><td></td><td><br><br><p class="submit"><input type="submit" id="submit" name="commit" value="register"></p><br><br><br></td></tr> </form> </table>
the validation js file is-
function discover() { var stu_name=document.forms["discover"]["name"].value; if (stu_name==null || stu_name=="" || stu_name.length<7) { alert("please provide full name"); return false; } }
i have included validation js file properly. validation not working. link forjsfiddle
try this
<script type="text/javascript"> function check() { var stu_name=document.forms["discover"]["stu_name"].value; if (stu_name==null || stu_name=="" || stu_name.length<7) { alert("please provide full name"); return false; } } </script> <form action="" method="post" name="discover" id="discover" onsubmit="return check();"> <input type="text" name="stu_name" id="stu_name" value="" /> <input type="submit" id="sub" /> </form>
Comments
Post a Comment