bba bba - 2 years ago 89
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.

Answer Source

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

$('input[name=my_name][value=123]').attr('checked', true); // or 'checked'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download