选中了哪个单选按钮? [英] which radio button is checked?
问题描述
我想检查选中了哪个单选按钮.然后,在问这个问题之前,我先看了这里的问题,然后他们说代码
I wanted to check which radio button is checked. Then, I looked at the questions in here before i asked this question and they said that the code
if(document.getElementById('number1').checked)
是答案.但是,我收到了错误消息使用未定义的常量文档-假定为'document'"和
is the answer. But, i got the error "Use of undefined constant document - assumed 'document'" and
Call to undefined function getElementById().
哪里出错了?我是否必须编写getElementById('number1').checked
的功能,因为它说未定义"?
谢谢
Where did it go wrong? Did i have to write the function of getElementById('number1').checked
because it says "undefined"?
Thanks
推荐答案
您的代码是Javascript.要检查PHP中单选按钮的值,它需要具有name
属性,该属性是通过GET或POST形式发送的.
Your code is Javascript. To check the value of a radio button in PHP, it needs to have a name
attribute, which was sent in a form either by a GET or POST.
// If form method='get'
if (isset($_GET['name_of_radio_group'])) {
// Show the radio button value, i.e. which one was checked when the form was sent
echo $_GET['name_of_radio_group'];
}
// If form method='post'
if (isset($_POST['name_of_radio_group'])) {
// Show the radio button value, i.e. which one was checked when the form was sent
echo $_POST['name_of_radio_group'];
}
这篇关于选中了哪个单选按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!