Reputation: 35
I have a table with radio buttons and some td's and when I click on a row the radio button in that row gets checked.
$("#usernames_table").on('click', 'tr', function (e) {
if (!$(e.target).is('input:radio')) {
$(this).find("input:radio:first").prop("checked", true).trigger("click");
}
});
Now every time a radio button gets checked I run an AJAX call and it works if I click directly on the radio button but not if I click on the row which trigger the function to make the radio button checked.
jQuery('#myform').on('change', 'input[name=information]:radio', function (e) {
Here is some code of my table
trHTML += '<tr><td><input type="radio" name="information" value="' + usernames[i] + '"></td></tr>'
I have no idea why it is not getting triggered: the table is inside #myform and then inside #usernames_table.
Upvotes: 1
Views: 57
Reputation: 388416
You need to fire change event after setting the checked property as your handler is listening to change event handler. Also changing the checked property programatically won't trigger change event.
$(this).find("input:radio:first").prop("checked", true).trigger("change");
Upvotes: 3