【发布时间】:2011-01-28 15:48:14
【问题描述】:
我目前有一个表单,在表单下方,我有一个复选框和一些单选按钮。这是复选框和单选按钮的代码:
<li id="discountCheckbox" class=" ">
<label class="desc" id="title416" for="Field416">
Discounts Available:
</label>
<div>
<span>
<input id="discountCheckbox" name="discountCheckbox" type="checkbox" class="field checkbox" value="Past Host Discount - 10%" tabindex="12" />
<label class="choice" for="Field416">Past Host Discount - 10%</label>
</span>
</div>
</li>
<li id="shipping1" class=" ">
<label class="desc" id="shippingChoice" name="shippingLabel" value="yahha" for="Field517_0">
Shipping Options
</label>
<div>
<input id="9281" name="9821" type="hidden" value="" />
<span>
<input id="shipping1" name="shipping1" type="radio" class="field radio" value="cost" tabindex="13" checked="checked" onclick="setShippingSpan('$2.00');" />
<label class="choice" for="Field517_0" >
$2.00 Shipping Fee</label>
</span>
<span>
<input id="shipping2" name="shipping1" type="radio" class="field radio" value="free" tabindex="14" onclick="setShippingSpan('$0.00');" />
<label class="choice" for="Field517_1" >
I will pick up the items (free shipping)</label>
</span>
</div>
</li>
在提交表单时,我有一个正在运行的文件 process.php。在该文件中,我使用$_POST["discountCheckbox"] 获取复选框的值。但是,我不知道如何获取单选按钮的值(确定选择了哪一个)。 我该怎么做?
【问题讨论】:
-
您有多个具有相同 ID 的元素。这是无效的 HTML。
-
我已经解决了这个问题。现在我该怎么办?
-
另外,清理您的 HTML 也很好,这样我们可以更快地为您提供帮助……这使得它有点难以阅读。最真诚的:)
-
您写了
$_POST,这意味着您使用的是PHP?这篇文章没有提到这一点,因为捕获值的解决方案包括使用 $_POST['shipping1'] 来获取单选按钮的值。例如看看这篇关于它的文章 (homeandlearn.co.uk/php/php4p10.html)
标签: javascript html forms post