mardi 29 décembre 2015

How to uncheck all checkboxes except on using jQuery?

I have a form that has multiple checkbox groups.

Each checkbox has a custom html 5 entity called itemtype

When the input of type="checkbox" changes, I need to check checkbox that was just selected. If the value of it's data-itemtype is equal to 'Skipper', I want to uncheck all other checkboxes that belong to the same group except for the one that was last check.

I have create a fiddle to show you what I have done along with the form http://ift.tt/1OYdnqS

I tried to do something like this but is is not working

    var skipper = $("input[name='"+inputName+"']:checkbox[data-itemtype='Skipper']");


    if( skipper.is(":checked")){

        $(this).attr('checked', false);

        skipper.attr('checked', true);

    }

Also, how can I tell the difference the input and the check box?

$(this) seems to be referring to the input it self not to the checkbox "which belongs to the input"

Thank you




Aucun commentaire:

Enregistrer un commentaire