javascript - 多种表单和单选按钮

标签 javascript php html

我正在设计一个测验软件,其中的问题以试卷的形式列出。用户假设只准确回答一个问题和一个答案。我的问题是,对于每个问题和 3 个选项,我都有不同的表格。提交后,我想知道在提交的各种表单中选中了哪个单选按钮。代码是这样的。

<html>
<form name="one" action="me.php" method="post">
<input type="radio" name=" subject " value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>
<form name="one" action="me2.php" method="post">
<input type="radio" name=" subject " value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>

<form name="one" action="me3.php" method="post">
<input type="radio" name=" subject " value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>

<form name="one" action="me4.php" method="post">
<input type="radio" name="subject" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="radio" name="options" value="some thing">
<input type="submit" value="submit">
</form>

</html>

谢谢

最佳答案

不要使用多种形式,而是这样做,

<html>
<form name="one" action="me.php" method="post">
<input type="radio" name="subject_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">


<input type="radio" name="subject_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">
<input type="radio" name="options_dbid" value="some thing">


<input type="submit" value="submit">
</form>

</html>

其中 dbid 是您的数据库。

确保 dbid 是您问题的 ID。(主题和选项应该相同。)

对于您帖子中的第一个问题,subject_1option_1 将选择该问题。

要访问 php 中的问题和答案,请在 php 中使用 explode()_

$arr[1] 将具有数据库 ID。您可以轻松地将答案与数据库进行匹配。

关于javascript - 多种表单和单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33705031/

相关文章:

javascript - 让我的 "beer"垂直进度条工作

javascript - 用 Javascript 突出显示单词,我错过了什么?

asp.net - 为什么 IE 和 Chrome 渲染 css border-bottom-width 不同?

html - 我的行内 block 元素没有正确排列

html - 溢出-y :hidden and overflow-x:hidden but how do I scroll down without the scroll bar

javascript - Android 浏览器中某些键没有按键事件

javascript - 标识符和变量之间的区别(在 JavaScript 中)

php - 计算每行 Union 和 Left Join 的评论

php - 使用 jQuery 控制一个页面与另一个页面

javascript - 是否可以在 Javascript 循环中更新浏览器窗口?