I am trying to attach the validation on a button click. I have:
<script>
$().ready(function() {
//
$("#btnAdd").click(function() {
$("#myForm").validate({
// $("#crap").rules("add", {required: true, messages: {required:"Required input"} });
rules: { crap: "required" },
messages: { crap: "required field"}
// $("#myForm").validate();
});
});
});
</script>
<form method="post" id="myForm" name="myForm">
<input type="text" name="crap" id="crap" class="required" />
<br />
<input type="button" name="btnAdd" id="btnAdd" value="add" />
</form>
now, if i change btnAdd to a submit type, it works. otherwise, it won’t. how can i call the validation on a button click ? thanks
validation happens on submit that is why it work..
do you not want to submit the form ?
you could invoke the submit function yourself
by chaining the submit call to the validate one ..
[EDIT] Actually the validate plugin has the form method which triggers the validation, so chain that instead of the submit.. (updated in code above)
http://docs.jquery.com/Plugins/Validation/Validator/form