jQuery re-checking check boxes
- by Jacob
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.