回声检查选中了哪个复选框 [英] Echo check on which checkbox was checked
本文介绍了回声检查选中了哪个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可以编辑内容的表格,这时,我将复选框的值回显到输入字段中,但是我宁愿保留原始复选框并显示选中了哪个复选框.
I have a form where i can edit the content, at this point i'm echo'ing the value of a checkbox into an input field but i rather keep the original checkbox's and show which one was checked.
<div class="col-sm-9">
<label class="checkbox-inline">
<input type="radio" class="px" name="radiochoice" id="radio11" class="radio" value="No Charge" />
<span class="lbl">No Charge</span>
</label>
<br>
</div>
<div class="col-sm-9">
<label class="checkbox-inline">
<input type="radio" class="px" name="radiochoice" id="radio7" class="radio" value="185.00" />
<span class="lbl">Networking: $185.00</span>
</label>
<br>
</div>
<div class="col-sm-9">
<label class="checkbox-inline">
<input type="radio" class="px" name="radiochoice" id="radio8" class="radio" value="125.00"/>
<span class="lbl">Mechanical: $125.00</span>
</label>
<br>
</div>
如果我回显该值,它将仅显示该值,那么如何显示已选中哪个复选框呢?
If i echo the value its just going to show the value, how do i show which checkbox was checked instead?
value=<?php echo $radiochoice;?>>
目标:
if ($radiochoice == "No Charge") {
echo '<div class="col-sm-9">';
echo '<label class="checkbox-inline">';
echo '<input type="radio" class="px" name="radiochoice" id="radio11" class="radio" value="No Charge" checked/>';
echo '<span class="lbl">No Charge</span>';
echo '</label>';
echo '<br>';
echo '</div>';
echo '<div class="col-sm-9">';
echo '<label class="checkbox-inline">';
echo '<input type="radio" class="px" name="radiochoice" id="radio7" class="radio" value="185.00" />';
echo '<span class="lbl">Networking: $185.00</span>';
echo '</label>';
echo '<br>';
echo '</div>';
echo '<div class="col-sm-9">';
echo '<label class="checkbox-inline">';
echo '<input type="radio" class="px" name="radiochoice" id="radio8" class="radio" value="125.00" />';
echo '<span class="lbl">Mechanical: $125.00</span>';
echo '</label>';
echo '<br>';
echo '</div>';
echo '<div class="col-sm-9">';
echo '<label class="checkbox-inline">';
echo '<input type="radio" class="px" name="radiochoice" id="radio9" class="radio" value="59.00" />';
echo '<span class="lbl">Remote half: $59.00</span>';
echo '</label>';
echo '<br>';
echo '</div>';
echo '<div class="col-sm-9">';
echo '<label class="checkbox-inline">';
echo '<input type="radio" class="px" name="radiochoice" id="radio10" class="radio" value="89.00" />';
echo '<span class="lbl">Remote 1 HR: $89.00</span>';
echo '</label>';
echo '<br>';
echo '</div>';
} elseif ($answer == 185.00) {
ETC ETC ETC
ETC ETC ETC
推荐答案
,但您每次添加的输入内容都不美观
while not elegant on every input you can add
<input type="radio" class="px" name="radiochoice" id="radio7" class="radio" value="185.00" <?php if($_POST['radiochoice'] =='185.00'){echo "checked='checked'";} ?>/>
相应地更改值,它可能是$ _GET,具体取决于表单操作
alter the value accordingly, and it may be $_GET, depending on form action
这篇关于回声检查选中了哪个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文