Jquery Tutorial: Select or deselect a radio button

Comment 1 Standard

Today was the first time I tried to do this and believe it or not many of the tutorials/examples I found on good ole Google didn’t work. So after about 45 minutes I finally found an example that worked for me. Hopefully you won’t spend as long looking for the answer as I did.

//select the radio button
$("input[name=your_field_name_here][value='the_value_of_that_field_here']").attr("checked","checked");

//deselect the radio button
$("input[name=your_field_name_here][value='the_value_of_that_field_here']").attr("checked","");

Reference:  Comment posted by JoaoLuiz at the bottom

Advertisements

One thought on “Jquery Tutorial: Select or deselect a radio button

  1. Apparently this is now the best way as of jQuery 1.6:
    $(this).prop(‘checked’, false);

    See http://api.jquery.com/prop/ for details. I think the only reason I’d want to deselect a radio button though is for doing debugging in development.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s