Getting and setting radio button values with JQuery

I figured I would share this because I found so many inconsistent hits on the internet searching for a solution. I have this dialog that I pop up and want to set the values and then retrieve the values once OK is hit using JQuery.

jquery-radio

The HTML is pretty straight forward:

jquery-html

The code to set the value from my model looks like this:

var $radios = $('input:radio[name=transition]');
$radios.filter('[value=' + model.options.transition +']').attr('checked', true);

The code to retrieve the value looks like this:

model.options.transition = $('input:radio[name=transition]:checked').val();

5 thoughts on “Getting and setting radio button values with JQuery

  1. Pingback: Getting and setting check boxes with jQuery | Bob's Blog

  2. Thank you so much for this code – I’ve been searching everywhere for how to replace the value for a radio button set with the value of another radio button set in a 2010 SharePoint form/page I’m coding in SP Designer using JQuery.

    Like

  3. Pingback: Blog stats for 2014 and what I learned | Bob's Blog

  4. Pingback: Thank you for a great 2015 and Happy New Year! | Bob's Blog

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