admin管理员组文章数量:1291048
I have two pages, in the first page I submit the form which contains Radio buttons.
From the second page, I try to read the responses from the Radio buttons using the $_POST.
The problem is when I hit submit, the $_POST in the second page reads NULL. But when I'm not disabling the Radio buttons in the first page the $_POST form the second page reads the data from the Radio butons correctly.
Is there any solution to make the $_POST reads the values of disabled Radio buttons?
I'm using this Javascript code to disable the radio buttons when the user clicks on it:
function disableRadio(groupName){
var radio=document.getElementsByName(groupName);
for(c=0;c<radio.length;c++)
radio[c].disabled=true;
}
Here is a simple code from each of the two pages.
Page1:
echo '<form action="Page2.php" method="post">',
"<input type='radio' name='Question1' value='1' onClick='disableRadio(Question1)' />",
"<input type='radio' name='Question1' value='2' onClick='disableRadio(Question1)' />",
"<input type='radio' name='Question1' value='3' onClick='disableRadio(Question1)' />",
"<div><input type='submit' value='Submit'></div>",
"</form>";
Page2:
$response=$_POST['Question1'];
echo $response;
Update to this question
When using the ReadOnly attribute, the Radio buttons in the group are still click-able. So, I decided to Disable the other Radio buttons. Is there a better solution, as I don't want the user to have the feeling that he is able to change the answer.
I have two pages, in the first page I submit the form which contains Radio buttons.
From the second page, I try to read the responses from the Radio buttons using the $_POST.
The problem is when I hit submit, the $_POST in the second page reads NULL. But when I'm not disabling the Radio buttons in the first page the $_POST form the second page reads the data from the Radio butons correctly.
Is there any solution to make the $_POST reads the values of disabled Radio buttons?
I'm using this Javascript code to disable the radio buttons when the user clicks on it:
function disableRadio(groupName){
var radio=document.getElementsByName(groupName);
for(c=0;c<radio.length;c++)
radio[c].disabled=true;
}
Here is a simple code from each of the two pages.
Page1:
echo '<form action="Page2.php" method="post">',
"<input type='radio' name='Question1' value='1' onClick='disableRadio(Question1)' />",
"<input type='radio' name='Question1' value='2' onClick='disableRadio(Question1)' />",
"<input type='radio' name='Question1' value='3' onClick='disableRadio(Question1)' />",
"<div><input type='submit' value='Submit'></div>",
"</form>";
Page2:
$response=$_POST['Question1'];
echo $response;
Update to this question
When using the ReadOnly attribute, the Radio buttons in the group are still click-able. So, I decided to Disable the other Radio buttons. Is there a better solution, as I don't want the user to have the feeling that he is able to change the answer.
Share Improve this question edited Jul 26, 2012 at 23:52 user1483799 asked Jul 25, 2012 at 21:11 user1483799user1483799 4094 gold badges8 silver badges17 bronze badges 1- Create hidden input fields and set their value to match the radio buttons. – j08691 Commented Jul 25, 2012 at 21:14
5 Answers
Reset to default 5Disabled inputs do not submit their values.
You could set them to be readonly
instead, if this behaviour suits your situation.
Q: Is there any way to get sound out of my handset after I've hit the "off" button?
A: No, try hitting "mute" instead :)
There's a difference between "disabled" (this input is turned OFF) and "readonly" (has a value, but user can't tamper with it):
- http://www.w3schools./tags/att_input_readonly.asp
'Hope that helps .. PSM
You can set a hidden value to use a proxy for the radio button, and depending on the radio button's state set it, that way you can still disable the radio button and always have a value for what you want.
You should use readonly
instead of disabled
on the input elements.
You may be better off using <input type="hidden">
, and if you really need the user to see what they submitted earlier then you can add a set of disabled radio buttons with no name to show it.
本文标签: phpCan39t POST values from disabled Radio buttonsStack Overflow
版权声明:本文标题:php - Can't $_POST values from disabled Radio buttons - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741508809a2382482.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论