Reputation: 17382
I want to get the ids of all the check boxes which are checked and enabled, ie those checkboxes which are disabled and checked, should not be counted.
Here is my code:-
var widgets_list = [];
$("#dialog-form input:checkbox:checked").map(function(){
widgets_list.push($(this).attr('id'));
});
The current code adds checkboxes which are disabled and checked, which I dont want. How do I add a functionality which will take into account only enabled checkboxes.
Upvotes: 0
Views: 82
Reputation: 5402
It's pretty simple.Just add enabled
.Something like this.
var widgets_list = [];
$("#dialog-form input:checkbox:checked:enabled").map(function(){
widgets_list.push($(this).attr('id'));
});
Upvotes: 0
Reputation: 67207
You can also use :enabled,
$("#dialog-form input:checkbox:checked:enabled").map(function(){
widgets_list.push($(this).attr('id'));
});
Upvotes: 0
Reputation: 123739
Try:
var widgets_list = $("#dialog-form input:checkbox:checked").map(function(){
if(!this.disabled)
return this.id;
}).get();
or
var widgets_list = $("input:checkbox:checked:not(:disabled)").map(function(){
return this.id;
}).get();
map is used to convert one collection to another collection in this case checkboxes to array of ids, so you can avoid a push which you would generally do with a loop (.each)
Upvotes: 4