Reputation: 1697
I'm trying to use the following JS that I found around here and since I have multiple forms on a page I would like to customize the function to only work with specific form ID.
In my case <form id="car" ...
// required checkboxes
var requiredCheckboxes = $(':checkbox[required]');
requiredCheckboxes.change(function(){
if(requiredCheckboxes.is(':checked')) {
requiredCheckboxes.removeAttr('required');
}
else {
requiredCheckboxes.attr('required', 'required');
}
});
Upvotes: 0
Views: 42
Reputation: 21759
You have to modify your query as follows in order to select only the checkboxes from your form:
var requiredCheckboxes = $("#car").find(':checkbox[required]');
Upvotes: 2