How to check radio button with radio button value

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

Answers (6)

Lewis
Lewis

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

user2674996
user2674996

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

sangram parmar
sangram parmar

Reputation: 8726

Try this:

$("input[name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked','checked')

Upvotes: 0

DjLeChuck
DjLeChuck

Reputation: 378

Just use this

$("[name=IS_INCOMEPROOF_VERFIED][value=NO]").attr("checked", true);

http://jsfiddle.net/W4286/

Upvotes: 0

Eswara Reddy
Eswara Reddy

Reputation: 1647

Try this

$("input[name='IS_INCOMEPROOF_VERFIED']").each(function(){
    if($(this).val() === 'NO') {
         $(this).attr('checked','checked');   
    }
});

Demo

Upvotes: 0

Matthijs
Matthijs

Reputation: 568

Try this:

$("input[name='IS_INCOMEPROOF_VERFIED'][value='NO']").attr('checked', true);

Working fiddle: http://jsfiddle.net/qKEgL/

Upvotes: 1

Related Questions