I have a database in which I get value 0 or 1 (No/Yes respectively).
How do I check/uncheck radio button and check its state in jQuery Mobile.
My code is below
HTML code
<label>Are you Mad? </label>
<fieldset data-role="controlgroup" data-type="horizontal">
<input data-mini="true" type="radio" name="rdIsBP" id="rdIsBPYes" value="" />
<label for="rdIsBPYes">YES</label>
<input data-mini="true" type="radio" name="rdIsBP" id="rdIsBPNo" value="choice-1" />
<label for="rdIsBPNo">NO</label>
</fieldset>
JavaScript code
function CheckRadioStateYNoo(val,rdButton){
try{
var radios = document.getElementsByName(rdButton);
for( i = 0; i < radios.length; i++ ) {
if(i==0)
{
if(val==1)
{
//radios[i].checked=true;
$("#" + rdButton + "Yes").attr ("checked", "checked");
alert('rdButton' + radios[i].checked);
}
}
else{
if(val==1)
{
radios[i].checked=true;
alert('rdButton' + radios[i].checked);
}
}
}
}
catch(e){alert(e);}
}
i tried many experiments only this code is working for me
val can be 0 for unchceck and 1 for checked in db.maybe some one find it useful
html code
js code