How to select only allowed fields using jquery

 $('#btnSelectAll').click(function() {
       $('.inputchbox').attr('checked', true);
 });

$('#btnCancel').click(function() {
     $('fieldset:not(:checked)').find("input,select,textarea").removeAttr('disabled');
 });

When canceling, do I only need to enable checked flags? Can I use something like this?

On the selectall button, I select all the checkboxes from my set of fields, but here I need to select only the checkboxes with the checkbox turned on and the checkboxes with disabling disabled. So the checkboxes are disabled in my field on boot by myself?

How to exclude disabled checkboxes?

+3
source share
3 answers

You can use an intermediate filter:

$('.inputchbox').filter(function() { return !this.disabled; }).attr('checked', true);

edit - or you can do as @sAc says and use a filter selector; I have a mental block that you probably shouldn't listen to me. This probably happened in childhood.

+1
source

(':checkbox:enabled') enabled.

:checked :enabled

+6

You can use several attributes at once, i.e.

input: Checkbox [name * = 'name']: checked: enabled

to check if a name is set with a name and a flag, but you should get the length to check in boolean form ie

if ($("input:checkbox[name*='name']:checked:enabled").length) {
                    isValid = true;
                }
+2
source

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


All Articles