Saturday, September 18, 2010

How to select a radio button in JQuery

To set a radio button value using JQuery, you need to set the the checked attribute. The name attribute will let you group the radio buttons and the id attribute will help you find the radio button using jQuery

function SetRadioButtonValueToThree()
{
$( "#radiobtn_3" ).attr( "checked" , "checked" );
}

<input type= "radio" name= "myradioGroup" id= "radiobtn_1" value= "1" checked= "checked" />One<br/>
<input type= "radio" name= "myradioGroup" id= "radiobtn_2" value= "2" />Two<br/>
<input type= "radio" name= "myradioGroup" id= "radiobtn_3" value= "3" />Three<br/>

No comments:

Post a Comment