jQuery re-checking check boxes

Posted by Jacob on Stack Overflow See other posts from Stack Overflow or by Jacob
Published on 2011-01-01T05:13:38Z Indexed on 2011/01/01 5:54 UTC
Read the original article Hit count: 217

Filed under:
|

Hi,

I having problems with re-checking some checkboxes after and ajax call updates a table.

I have a table of what the project calls 'shares'.

I want to:

1) check for and save any checked shares to an array
2) Do my ajax call to update the table of shares
3) Re-check any there we checked before the ajax update.

My code is not working and I can't see why?

Any tips, help or advise much appreciated.

// Array to hold our checked share ids
var savedShareIDs = new Array();

// Add checked share ids into array
$("input:checkbox[name=share_ids]:checked").each(function() {  
 savedShareIDs.push($(this).val());  
});     

// Do ajax update
Dajaxice.pagination_shares('Dajax.process',{'id':1, 'page':1})

// Re-check any that were checked before ajax update
$("input:checkbox[name=share_ids]").each(function()  
{  
 if ( $.inArray( $(this).val(), savedShareIDs) > -1 ) {   
  $(this).attr('checked',true)  
 }  
});

The problem is the checkboxes are not checking.
I'm pretty sure the loop is working and the inArray check works.

Just not checking the checkboxes. Can anyone see where I'm going wrong?

Thanks.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about checkboxes