Computer Guy
Computer Guy

Reputation: 411

mvc3 and jquery - check RadioButtonFor

I have 3 radio buttons that are rendered in an mvc3 View. I'm using a view model and the following is View.aspx page where the radioButtonFor is rendered:

<%= Html.RadioButtonFor(model => model.Input.YesNoMaybe, item.Value, new { id = String.Format("Input_YesNoMaybe_{0}", item.Value) })%>

Can someone please help me figure out how to simply access and select the 2nd of the 3 radio buttons to checked using jQuery?

So far I've tried multiple variations of the following:

$("input[name='Input.YesNoMaybe_1']").attr('checked', 'checked');

This is HTML being rendered:

<div id="divEscrowFeeSplit">
<input type="radio" value="1" name="Input.YesNoMaybe" id="Input_YesNoMaybe_1" data-val-required="required." data-val-range-min="1" data-val-range-max="2147483647" data-val-range="select a valid option" data-val-number="Must be a number." data-val="true">
<label for="Input_YesNoMaybe_1">Yes</label>&nbsp;
<input type="radio" value="2" name="Input.YesNoMaybe" id="Input_YesNoMaybe_2">
<label for="Input_YesNoMaybe_2">No</label>&nbsp;
<input type="radio" value="3" name="Input.YesNoMaybe" id="Input_YesNoMaybe_3" checked="checked">
<label for="Input_YesNoMaybe_3">Maybe</label>&nbsp;

Upvotes: 0

Views: 847

Answers (1)

Chandu
Chandu

Reputation: 82903

Try this:

$("#Input_YesNoMaybe_1").attr('checked', 'checked');

Upvotes: 1

Related Questions