Check or Uncheck All Checkboxes using jquery

Check or Uncheck All Checkboxes using jquery

Postby tomrff » Thu Apr 28, 2011 1:40 pm

There are different methods to check and uncheck the check boxes.

suppose that you have checkboxes like that

<input type=”checkbox” value=”1″ name=”Items” id=”Items1″ />
<input type=”checkbox” value=”2″ name=”Items” id=”Items2″ />
<input type=”checkbox” value=”3″ name=”Items” id=”Items3″ />
<input type=”checkbox” value=”1″ name=”Items” id=”Items4″ />

1- using attr() function.
$(‘#checkall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,true);
});
$(‘#uncheckall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,false);});

2- using attr() and removeAttr()funstions
$(‘#checkall’).click(function(){
$(“input[@name='Items']:checked”).attr(‘checked’,true);
})
$(‘#uncheckall’).click(function(){
$(“input[@name='Items']:checked”).removeAttr(‘checked’);})

Note- if your checkbox name is array type, then simple replace Items to Items[]
tomrff
 
Posts: 33
Joined: Sat Jan 08, 2011 10:12 pm

Return to JQuery

Who is online

Users browsing this forum: No registered users and 1 guest

cron