php - How to check the radio button by default -


here radio button.

<input type="radio" id="myradio" value=1> <input type="radio" id="myradio" value=2> <input type="radio" id="myradio" value=3> 

in script want check third radio button

$('#myradio').attr('checked',true); not checking radio button.

var target = '3';

how can check radio button id="myradio" , value=3 ?

http://api.jquery.com/prop/

concerning boolean attributes, consider dom element defined html markup , , assume in javascript variable named elem:

elem.checked    true (boolean) change checkbox state $( elem ).prop( "checked" )     true (boolean) change checkbox state elem.getattribute( "checked" )  "checked" (string) initial state of checkbox; not change $( elem ).attr( "checked" ) (1.6)   "checked" (string) initial state of checkbox; not change $( elem ).attr( "checked" ) (1.6.1+)    "checked" (string) change checkbox state $( elem ).attr( "checked" ) (pre-1.6)   true (boolean) changed checkbox state 

correct:

<input type="radio" id="myradio3" value=3> $("myradio3").checked 

it doesnt make sense if name 3 elements same id. rather should use classes.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -