Help with validation attached to a button

NickMalloy
NickMalloy used Ask the Experts™
on
I'm trying to use the Jquery validation, but I only want certain fields to be attached to certain buttons. What is the best way to do this? I tried a simple click command surrounding it, but it doesn't work. What can I do?

   $("ctl00$MainContent$btnAddItem").click(function () {

        $("#aspnetForm").validate({
            invalidHandler: function (e, validator) {
                var errors = validator.numberOfInvalids();
                if (errors) {
                    var message = errors == 1
                              ? 'You missed 1 field. It has been highlighted below'
                              : 'You missed ' + errors + ' fields.  They have been highlighted below';
                    $("div.error span").html(message);
                    $("div.error").show();
                } else {
                    $("div.error").hide();
                }
            },
            focusInvalid: false,
            rules: {

                ctl00$MainContent$txtNewManu: "required",
                ctl00$MainContent$txtNewProd: "required",
                ctl00$MainContent$rdbProdType: "required",
                ctl00$MainContent$txtProdDesc: "required",
                ctl00$MainContent$rdbProdItemsDRR: "required",
                ctl00$MainContent$txtProdLike: "required",

                ctl00$MainContent$txtOldManu: "required",
                ctl00$MainContent$txtOldProd: "required"
                //          
            },
            messages: {
                ctl00$MainContent$txtName: "Please enter your Full Name"
                //          
            }

        });

    });
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can use validator's dependency required methods. This allow you to pass one condition to the validator.

http://docs.jquery.com/Plugins/Validation#Options_for_the_validate.28.29_method

http://docs.jquery.com/Plugins/Validation/Methods/required

Let me know if you need more details.
NickMalloySystems Lead

Author

Commented:
I could be completely off on my readings, but I tried this

  ctl00$MainContent$txtNewManu: {
                    required: function () {
                        $("#btnAddItem").attr('click') == "true"
                    }
                },

but it still validates this field when the other button is clicked???
On click of btnAddItem set set Add Button clicked flag to true.

Ex:

ctl00$MainContent$txtNewManu: {
                    required: function () {
                        $("#btnAddItemClicked"). == "true"
                    }
                },

And on click on btnAddItem
execute below code

 $("#btnAddItemClicked") = "true";

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial