validating only few fields for any specific submit button
I am using jQuery Validation plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-validation/ )
I have a very odd scenario in front of me.
I have one form, with 5 different submit buttons
<form id="frm1" name="frm1" method="post" action="save.ph开发者_如何转开发p">
------- input fields here---
<input type="submit" name="submit" value="update account info">
------- input fields here---
<input type="submit" name="submit" value="update address info">
------- input fields here---
<input type="submit" name="submit" value="update credit-card info">
------- input fields here---
<input type="submit" name="submit" value="update bank info">
------- input fields here---
<input type="submit" name="submit" value="update other info">
</form>
Now, for each submit button, I need to validate a few fields (and not all fields)
Say for "update account info" submit, I need to validate following input fields with following ids:
cust_fname
cust_lname
cust_age
Say for "update other info" submit, I need to validate following input fields with following ids:
married
childerns
How can I achieve following?
create 5 separate forms is the most easy way to do this. Then you can bind a different specific validation to each form.
Or you can bind a validation to each click on a submit button. assuming you update your submitbutton to:
<input type="submit" id="button_1" name="submit" value="update account info">
Then with jquery you can bind this with:
$("#button_1").live("click", function() {
$("#frm1").validate({
rules: {
cust_fname: "required", // of course set different options for every field
cust_lname: "required",
cust_age: "required"
}
});
});
And do this for every button.
edit: Live has been deprecated.
$("#button_1").on("click", function() {
$("#frm1").validate({
rules: {
cust_fname: "required", // of course set different options for every field
cust_lname: "required",
cust_age: "required"
}
});
});
精彩评论