Automatically select a radio button in a field

I have a set of fields with radio (question options), I want to pre-select the switch in the parameter management group programmatically on the show page, here is the control group:

<fieldset data-role="controlgroup" id="options"> <input type="radio" name="radio-choice-1" id="optiona" value="a" checked="checked" /> <label for="optiona" id="labela">Ondo</label> <input type="radio" name="radio-choice-1" id="optionb" value="b" /> <label for="optionb">Lagos</label> <input type="radio" name="radio-choice-1" id="optionc" value="c" /> <label for="optionc">Abuja</label> <input type="radio" name="radio-choice-1" id="optiond" value="d" /> <label for="optiond">Kogi</label> <input type="radio" name="radio-choice-1" id="optione" value="e" /> <label for="optione">Niger</label> </fieldset> 

I tried the following:

 var sel = questions[indexNo].correct; $("#option" + sel).prop("checked", true) $("#option"+ sel).is(":checked"); 
+4
source share
1 answer

Working example: http://jsfiddle.net/Gajotres/aawNj/

 $(document).on('pagebeforeshow', '#index', function(){ $( "#optiona" ).prop( "checked", false ).checkboxradio( "refresh" ); $( "#optionb" ).prop( "checked", true ).checkboxradio( "refresh" ); }); 

or another working example: http://jsfiddle.net/Gajotres/EFzxj/

 $(document).on('pagebeforeshow', '#index', function(){ $( "#optionb" ).prop( "checked", true ); $('#content').trigger('create'); }); 
+5
source

Source: https://habr.com/ru/post/1484346/


All Articles