I have two set of radio buttons in html form button
and button1
. I am using below code to
1.keep the default value checked (question1
for first set and answer2
for next set)
2.keep user radio button selection after the form submit
<div id="button_set1">
<input onClick="show_seq_lunid();" type="radio" name="button" value="Yes" <?php if(isset($_POST['button']) && $_POST['button'] == 'Yes') echo ' checked="checked"';?> checked /><label>question1</label>
<input onClick="show_list_lunid();" type="radio" name="button" value="No" <?php if(isset($_POST['button']) && $_POST['button'] == 'No') echo ' checked="checked"';?> /><label>answer1</label>
</div>
<div id="button_set2">
<input onClick="os_hpux();" type="radio" name="button1" value="Yes" <?php if(isset($_POST['button1']) && $_POST['button1'] == 'Yes') echo ' checked="checked"';?> /><label>question2</label>
<input onClick="os_others();" type="radio" name="button1" value="No" <?php if(isset($_POST['button1']) && $_POST['button1'] == 'No') echo ' checked="checked"';?> checked /><label>answer2</label>
</div>
Here if i use below code, the second radio button button1
is not sticking on to the user selection after form submit, it changing back to its default checked state.ie answer2
. But the first set of radio buttons work fine.
If I remove the default checked
option from the code, both radio buttons working fine after form submit. How can I keep the radio button checked after form submit while using checked
default option for radios
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…