Reputation: 45
I am having radio button with value YES and NO.Like this
<input type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="YES" onclick="IS_INCOMEPROOF_VERFIED1()"/>
<input type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="NO" onclick="IS_INCOMEPROOF_VERFIED1()"/>
How to select radio box by using radio button value.For example i want radio button to be selected for NO value.It should come like this
<input type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="NO" onclick="IS_INCOMEPROOF_VERFIED1()" cheked="checked"/>
Upvotes: 1
Views: 169
Reputation: 789
The jQuery selector to select the radio button with a value of NO
(assuming the name is needed) would be:
$("input[type='radio'][name='IS_INCOMEPROOF_VERFIED'][value='NO']")
To make it checked (using jQuery 1.6+) you would use:
$("input[type='radio'][name='IS_INCOMEPROOF_VERFIED'][value='NO']").prop("checked", true);
To make it checked (using < jQuery 1.6) you would use:
$("input[type='radio'][name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked', 'checked');
Here is a working jsFiddle example.
To make your code cleaner and allow for easier selection it would be advisable to give all of your input
elements unique IDs.
Upvotes: 0
Reputation:
why do not you just give it id and select it
<input id"rdNo" type="radio" name="IS_INCOMEPROOF_VERFIED" data-role="none" value="NO" onclick="IS_INCOMEPROOF_VERFIED1()"/>
$("#rdNo")...;
Upvotes: 0
Reputation: 8726
Try this:
$("input[name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked','checked')
Upvotes: 0
Reputation: 378
Just use this
$("[name=IS_INCOMEPROOF_VERFIED][value=NO]").attr("checked", true);
Upvotes: 0
Reputation: 1647
Try this
$("input[name='IS_INCOMEPROOF_VERFIED']").each(function(){
if($(this).val() === 'NO') {
$(this).attr('checked','checked');
}
});
Upvotes: 0
Reputation: 568
Try this:
$("input[name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked', true);
Working fiddle: http://jsfiddle.net/qKEgL/
Upvotes: 1