Selecting correct radio button using jQuery
I have 4 radio buttons and a data table that has a row that matches each radio button value. When I select a data table row the corresponding radio button is selected. I can cycle through all data table rows and watch each corresponding radio button get selected. If I select a data table row that has the same radio button value of a previously selected row or go back and re-select a row, the radio buttons stop being selected. Can someone tell/show me why my radio buttons are not being selected the 2nd time through?
- $('#reviewerDatatable tbody').on('click', 'tr', function () {
var rowData = table.row(this).data();
- $.each(rowData, function (name, val) {
var $el = $('[name="' + name + '"]'),
type = $el.attr('type');
- switch (type) {
case 'radio':
- console.log(val);
$el.filter('[value=' + val + ']').attr('checked', true);
break;
- case 'date':
var now = new Date(val);
var day = ("0" + now.getDate()).slice(-2);
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var formattedDate = now.getFullYear() + "-" + (month) + "-" + (day);
$el.val(formattedDate);
break;
- default:
$el.val(val);
}
});
});