php单选框值
鉴于使用 html 单选框时,要将值发送到 php 脚本,只有选定的值会发送到 php 脚本,仍然成立。
当我只对发送到 php 脚本的所选值感兴趣时,我是否还需要检查用户是否选择了某些内容,如果用户没有选择任何内容,我们什么都不做,或者我想我可以提示用户选择某些内容。
如果是这样,处理无线电盒的最佳方法是什么?
<!--Using the radio box, a single selected value is sent to the php script for processing-->
<td width="100px" height="30px">
<input type = "radio"
name = "selection"
value = "Lays" />Lays Chips 0.99c<br />
<input type = "radio"
name = "selection"
value = "Ruffles" />Ruffles $1.85<br />
Given that when using an html radio box, to send values to a php script, only the selected values is sent to the php script, still holds true.
Do I still need to check that the user has selected something, when I am only interested in the selected value being sent to the php script, if the user does not select anything we do nothing or I guess I could prompt the user to select something.
If so, whats the best way to handle this with regards to radio boxes?
<!--Using the radio box, a single selected value is sent to the php script for processing-->
<td width="100px" height="30px">
<input type = "radio"
name = "selection"
value = "Lays" />Lays Chips 0.99c<br />
<input type = "radio"
name = "selection"
value = "Ruffles" />Ruffles $1.85<br />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
即使不从单选框中选择选项,用户也可以单击“提交”按钮。
如果可以在没有选择的情况下发送表单,并且您只想在未选择任何内容时执行不同的操作(或忽略它),则可以执行以下操作:
OTOH,如果您想阻止在没有选择的情况下提交,则需要使用一些 JavaScript 来完成它。
The user will be able to click the "submit" button even without selecting an option from your radiobox.
If it's ok to send the form without a selection and you just want to do something different (or ignore it) when nothing is selected, you can do this:
OTOH, if you want to prevent submiting without a selection, you will need to use some JavaScript to do it.
即使未设置
radiobox
,您仍然可以将表单发送回服务器。当然,除非您的 Javascript 在未设置radiobox
的情况下阻止用户点击提交表单。因此,在进行操作之前,您仍然需要检查
radiobox
是否已设置。Even if the
radiobox
is not set, you can still post the form back to the server. Unless, of course, you have Javascript that prevents one from clicking on the submit form if theradiobox
is not set.So, you still need to check whether the
radiobox
is set or not, before working on it.