【问题标题】:How to associate Radio Button value with Input Field如何将单选按钮值与输入字段相关联
【发布时间】:2016-03-07 15:45:27
【问题描述】:

我正在创建一个测验应用程序...

我创建了一个问题文本区域,以及一些选项输入字段..

每个输入字段都有一个单选按钮,如果用户点击它,它会将关联的输入字段视为正确答案..

我为每个输入字段创建了一些输入字段和单选按钮

<div id="items">
    <input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct" value="yes"/> <br><br>
    <input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct" value="yes"/>
</div>

当我提交此表单时,它会将yes 与每个选项一起存储。我无法理解如何只存储 1 个输入字段的值。

请指导我 谢谢。

【问题讨论】:

    标签: php html forms


    【解决方案1】:

    如果你得到选项的值是 input1 答案是 input1 或者如果选项值是 input2 答案是 input2

    <input type="radio" name="options" value="input1">Is Correct<br>
    <input type="radio" name="options" value="input2">Is Correct
    

    input1 是文本框 1 的名称

    input2 是文本框 2 的名称

    获取表单帖子的价值:-

    $nam=$_POST['options'];
    $answer=$_POST[$nam];
    

    【讨论】:

      【解决方案2】:

      您可以使用如下输入:

      <div id="items">
          <input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct[]" value="yes"/> <br><br>
          <input class="form-control" type="text" name="options[]" required /> Is Correct: <input type="radio" name="is_correct[]" value="yes"/>
      </div>
      

      【讨论】:

        猜你喜欢
        • 2011-06-09
        • 1970-01-01
        • 1970-01-01
        • 2011-05-04
        • 2019-10-24
        • 1970-01-01
        • 2012-01-04
        • 2011-05-18
        • 2010-11-14
        相关资源
        最近更新 更多