【发布时间】:2015-02-17 03:10:23
【问题描述】:
我有多个链接在一起的单选按钮。我想根据是否单击/设置每个单选按钮来设置它的值
编辑我已经包含了一组单选按钮的完整代码。一组,因为它们都被称为相同的名称。
>
<td><br><input type="radio" name="meal1" <?php if (isset($meal2)){
echo "checked", "value = '1'";
} else {
echo "value = '0'";
}
?>>
</td>
<td><br><input type="radio" name="meal1" <?php if (isset($meal3)){
echo "checked", "value = '1'";
} else {
echo "value = '0'";
}
;?>>
</td>
<td><br><input type="radio" name="meal1" <?php if (isset($meal4)){
echo "checked", "value = '1'";
} else {
echo "value = '0'";
}
;?>>
</td>
编辑此代码现在与之前的代码不同,只是为了回显每个代码的输出
if(isset($_POST['order'])){
if(!isset($_POST['meal1'])){
echo "Radio buttons not set.";
} else {
$meal1 = $_POST['meal1'];
$meal2 = $_POST['meal1'];
$meal3 = $_POST['meal1'];
$meal4 = $_POST['meal1'];
print_r($meal1);
print_r($meal2);
print_r($meal3);
print_r($meal4);
}
当我在单击单选按钮后执行下面的代码时。输出为 0,0,0,0。我希望输出为 1,0,0,0 因为我单击了第一个单选按钮。
【问题讨论】:
-
嗯,我没有在您发布的代码中看到您设置 $_POST['meal1'] 的值。
标签: php html radio-button