0

How can I add Jquery Validation for multiple textboxes with same name, when their corresponding checkboxes are checked

    Jquery:
     $("input:[name='abc']").change(function() {
                var method = $(this).val();
                if ($(this).is(':checked')) {
                    $("#" + method).spinner({
                        'disabled': false
                    });
                    console.log(method);
                    $("#" + method).rules("add",{
                            range: [1, 99],
                            required : true,
                            messages: {
                                    range: "Please enter a value between 1 and 99",
                                    required: "Please give a value for " + method
                            }
                    });
                    $("#" + method).val(1);
                } else {
                    $("#" + method).spinner({
                        'disabled': true
                    });
                    console.log(method);
                    $("#" + method).rules('remove','range');
                    $("#" + method).rules('remove','required');
                    $("#" + method).val(0);
                }
            });

Trying to add and remove rules to textboxes depending upon the checkbox change event.

Sparky
  • 98,165
  • 25
  • 199
  • 285
Pavan
  • 31
  • 1
  • 3
  • Why not have unique names? – Rahul Desai Feb 09 '15 at 06:47
  • Since I am doing both front-end and back-end validation, There is a necessity to validate with names. Back-end validation is happening with perl – Pavan Feb 09 '15 at 07:07
  • Can you include the code for what you have done. So we could look more into the issue.And have a clear picture of what you are attempting to do. – Runcorn Feb 09 '15 at 07:16
  • @ArunprasanthKV, the jQuery Validate plugin mandates that all fields considered for validation have a unique name. – Sparky Feb 09 '15 at 16:22

1 Answers1

0

How can I add jQuery Validation for multiple textboxes with same name ...

You can not use jQuery Validate for this.

This plugin internally uses the name attribute to keep track of all form elements, therefore, all name attribute values must be unique. There is no workaround to this hard-coded requirement.

Sparky
  • 98,165
  • 25
  • 199
  • 285