Home » » How To Select A Radio Button Using JQuery (Dynamically) ?

How To Select A Radio Button Using JQuery (Dynamically) ?

Rendyon | 9:34 AM | 0 comments
It is very simple to select a radio using JQuery dynamically. Here is the example:


<input type="radio" name="sex" value="Male">Male</input>
<input type="radio" name="sex" value="Female">Female</input>

If you want to select radio button (Male)

$('input:radio[name=sex]:nth(0)').attr('checked',true);
or
$('input:radio[name=sex]')[0].checked = true;

Radio button index starts from 0, means for Male index will be 0 and for Female 1.
If you want to select radio buton(Female)


$('input:radio[name=sex]:nth(1)').attr('checked',true);
or
$('input:radio[name=sex]')[1].checked = true;

If you want to get selected  radio button value


$('input:radio[name=sex]:checked').val();

Check live example here: http://jsfiddle.net/jeetu_verma11/tgXKd/
Share this article :

0 comments:

 
Copyright © 2011. Find Updates - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger