bba bba - 5 months ago 6x
Javascript Question

Checking a radio button in JQuery

I need to problematically (do you mean programmatically?) check a radio button given its value. The form has an

and the input type obviously has a name (but no id). The only code I managed to get working so far is:

$('input[name=my_name]:eq(1)').attr('checked', 'checked');

But I'd like to be able to check it by explicitly providing the value.


So you want to select the radio which has a particular value:

$('input[name=my_name][value=123]').attr('checked', true); // or 'checked'