jeudi 8 janvier 2015

Try to check a checkbox based on values in a table

I am trying to use jQuery to loop over rows in a table, if the first td has a certain value then look for a checkbox on that row and check it.



$('#table1').find('tr').each(function(){
var prod = $(this).find('td:first').text();
if(prod == 'string value'){
$(this).find('input[type=radio]').prop('checked', true);
alert(prod);
}
});


But this does not work. The alert shows that the text matches that in the first cell, but it does not tick the radio button in the last cell. Not sure what i am doing wrong with this


I use a similar piece of code to select the checkbox based on clicking the row, which works fine.



$('#table1').find('tr').click( function(){
var row = $(this).find('td:first').text();
$(this).find('input[type=radio]').prop('checked', true);
});


Any help would be much appreciated.





Aucun commentaire:

Enregistrer un commentaire