jquery - validating the form is not working -
my form validation not firing...if try submit form without entering should validate in case accept form.
<script src="scripts/jquery-1.4.4.min.js" type="text/javascript"></script> <script src="scripts/jquery.validate.min.js" type="text/javascript"></script> <script> $(document).ready(function () { $("#register").click(function (event) { // validate comment form when submitted // validate signup form on keyup , submit $("#form1").validate({ rules: { firstname: "required", lastname: "required", //city: "required", state: "required", country: "required" }, messages: { firstname: "please enter firstname", lastname: "please enter lastname", //city: "please enter valid email address", country: "please select country" } }); $("#form1").validate({ submithandler: postdata }); function postdata() { $.ajax(url, { id: '1' }, function (data, textstatus) { //alert(textstatus); }); } }); }); </script> <div id="content-main"> <div class="main-inner"> <form id="form1" class="tooltip hascorners" name="form1" action="http://site.com/" onsubmit="return false;" method="post"> <fieldset> <div class="fontweight7"> <input type="radio" value="1" name="pledge_level" class="required"> <p class="radiotext"> iam on vacation.</p> <label for="level1" class="error"> please select</label> </div> <p class="required-msg"> fields below required</p> <div class="subcolumns paragraph"> <div class="lefty"> <div class="fontweight7"> <label for="first_name"> first name:</label> <input id="first_name" class="text hascorners required" name="first_name" type="text" maxlength="200" value=""> <label for="level1" class="error"> please enter name!</label> </div> </div> <div class="cdc-left"> <div class="fontweight7"> <label for="last_initial"> last initial:</label> <input id="last_initial" class="text hascorners required" name="last_initial" type="text" maxlength="200" value=""> <label for="level2" class="error"> please enter last initial!</label> </div> <rest of code here .... > </div> </div> <input id="register" name="register" value="submit form" type="submit">
the .validate
should done once document ready, not on click of button. take out there.
e.g.
$(document).ready(function () { $("#form1").validate({ rules: { firstname: "required", lastname: "required", //city: "required", state: "required", country: "required" }, messages: { firstname: "please enter firstname", lastname: "please enter lastname", //city: "please enter valid email address", country: "please select country" }, submithandler: postdata }); }); }); function postdata() { $.ajax(url, { id: '1' }, function (data, textstatus) { //alert(textstatus); }); }
hths,
charles
Comments
Post a Comment