javascript - .validate() not working JQuery -
i have problem regarding in validation in html. i'm using .validate() of validation plugin not working me. can me problem? have 2 names in each of . array of data used in inserting in database. conflict? should since required need use array in inserting data database? try put "#" , "data[0]" in rules still not worked.
note: validation.js served validation plugin i've downloaded online. jquery validation plugin 1.11.1. , jquery.js served jquery 1.8.3.
here's code.
<html> <head> <script type="text/javascript" src="jquery.js"></script> <script src="jquery-ui-1.10.4.custom/js/jquery-ui-1.10.4.custom.min.js"></script> <script src="loginbouncy.js"></script> <script src="modal.js"></script> <script type="text/javascript" src="validation.js"></script> <script src="validate.js"></script> <form id="mainform" name="mainform" method="post" action="signup2.php"> <input type="text" name="data[]" id="fname" name="fname" placeholder="first name"/> <input type="text" name="data[]" id="lname" name="lname" placeholder="last name"/> <input type="text" name="data[]" id="mname" name="mname" placeholder="m.i."/> <input type="text" name="data[]" id="sadd" name="sadd" placeholder="street"/> <input type="text" name="data[]" id="tadd" name="tadd" placeholder="town/city"/> <input type="text" name="data[]" id="padd" name="padd" placeholder="province/state"/> <input type="text" name="data[]" id="user2" name="user2" placeholder="your username"/> <input type="password" name="data[]" id="pass2" name="pass2" placeholder="your password"> <input id="captcha" name="captcha" type="text" name="captcha" placeholder="insert captcha"> <img id="imgcaptcha" src="captcha.php" /><br> <input type="text" name="data[]" id="email" name="email" placeholder="your email"/> <input type="button" id="btnsignup" placeholder="" onclick=""/> </input> <p id="confirm" style="font-size:15pt; position:absolute; top:450px; left:850px; ">dfgfdgdf</p> </form> </html>
my validate.js
$(document).ready(function(){ $('#btnsignup').click(function(){ $('#mainform').validate({ rules: { fname: { required: true, minlength: 7 } }, success: function(){ alert("valid"); } }); }); });
there multiple problems.
the validator uses name of input field, have 2 name attributes in input field remove name="data[]"
, should <input type="text" id="fname" name="fname" placeholder="first name" />
the validation automatically applied on form submit event change btnsignup
type="submit"
<input type="submit" id="btnsignup" placeholder="" value="sign up" />
also validate framework should initialized on dom ready, not in click handler
jquery(function ($) { $('#mainform').validate({ rules: { fname: { required: true, minlength: 7 } }, success: function () { alert("valid"); } }); $('#btnsignup').click(function () { }); });
demo: fiddle
Comments
Post a Comment