0

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');
        }
    });
Community
  • 1
  • 1
WayBehind
  • 1,607
  • 3
  • 39
  • 58

1 Answers1

2

You have to modify your query as follows in order to select only the checkboxes from your form:

var requiredCheckboxes = $("#car").find(':checkbox[required]');
taxicala
  • 21,408
  • 7
  • 37
  • 66
  • Thank you. I'm sure it is correct, however for some reason it is not working with my form. First I thought it was related to having multiple forms but I think there may be some other problem. – WayBehind Jun 24 '15 at 21:19
  • The issue is that I'm using a custom drop-down checkbox menu. When I remove the dropdown functionality, everything works OK. I'm trying to change the dropdown to div box with scroll so the user can select and check everything that applies. Thank you again for your help! – WayBehind Jun 24 '15 at 21:53