Check field with jquery only when checkbox selected

I have several checkboxes with the same name, and the last checkbox is basically β€œOther” with an empty text box next to it. I use jquery validation and want a blank text box to be needed when selecting a check box for another.

Not sure how to do this with checboxes with the same name.

Thank.

+3
source share
2 answers

Flags have the same name but different meanings. This way you can find the selected ones and then check the values ​​for a specific one. I did something similar with the switches. Here, one of my rules specifying the daypattern field is required if the radio object recurpattern is set to day.

        daypattern: {
            required: 
                function(element){
                    return ($("input[name='recurpattern']:checked").val() == 'day')
                }

        }

In your case, your checkbox set has an array in your checkbox.val () file. Therefore, you verify that your test value is in this array.

+2
source

:last - (http://api.jquery.com/last-selector/) DOM $(".myOtherInput").prev(), . class="required".

0

Source: https://habr.com/ru/post/1737395/


All Articles