Reputation: 1353
I have 4 options:
<input type="radio" name="tag" value="1"/>
<input type="radio" name="tag" value="2"/>
<input type="radio" name="tag" value="3"/>
<input type="radio" name="tag" value="4"/>
I have written a previous page function in jquery which returns the option already selected :
var option_selected = could be 1,2,3 or 4;
$('#previous').click(function (){
});
Please tell me how is that possible when I click this previous button the option already selected should be selected. What should I add in this function to do so?
Upvotes: 2
Views: 245
Reputation: 1
You can try it!
$('input:[name="tag"],[name="radio"],[value="' + option_selected + '"]').prop('checked', true);
Upvotes: 0
Reputation: 124277
$('input:radio[name="tag"][value="' + option_selected + '"]').prop('checked', true);
Upvotes: 0
Reputation: 87073
Try this:
$('input:radio[name="tag"][value="' + option_selected + '"]').prop('checked', true);
Read about .prop()
$('input:radio[name="tag"][value="' + option_selected + '"]')
select the input[type=radio]
with name=tag
and has value
equal to option_selected
.
Upvotes: 2