【问题标题】:RadioButtons in phpphp中的单选按钮
【发布时间】:2016-10-17 01:50:42
【问题描述】:

我有一个表格:

    <form  action= "catrand.php" method="POST" name="form">
    <h4>How mach text need to print?</h4>
    <input type="text" onkeyup="validate(this)" name="inp"> <script> function validate(inp) { inp.value = inp.value.replace(/[^\d,.]*/g, '') .replace(/([,.])[,.]+/g, '$1') .replace(/^[^\d]*(\d+([.,]\d{0,5})?).*$/g, '$1'); } </script>
    <h4>Select how print text</h4>
<input type="radio" name="b001" value="First"><font>text</font>
<input type="radio" name="b001" value="Second"><font>check</font>
<input type="radio" name="b001" value="Last"><font>radio</font>
    <h4>Input text</h4>
    <input type="text" name="inp1">
    <input type="text" name="inp2">
    <input type="text" name="inp3">
    <p><input type="submit"></p>    
    </form>

和php代码:

for($i=1;$i<=$number;$i++)
    {
        switch($_POST['b001']) {
            case "Last":
            {
                echo "<input type=\"radio\" onclick=\"uncheck_radio(this)\" value=\"First\" \"name=\"h001\">" .$numberone; 
                echo "<input type=\"radio\" onclick=\"uncheck_radio(this)\" value=\"Second\" \"name=\"h001\">".$numbertwo; 
                echo "<input type=\"radio\" onclick=\"uncheck_radio(this)\" value=\"Third\" \"name=\"h001\">".$numberthree."</br>";
                break;
            }


}           
    }

但尽管单选按钮的名称相同,但我可以标记两个或更多单选按钮。为什么?我的代码有什么问题?

【问题讨论】:

    标签: php html radio-button


    【解决方案1】:

    这里不需要转义引号:\"name= 尝试仅使用 name=

    【讨论】:

    • 很高兴为您提供帮助!顺便说一句,您的英语可以在这里提高:How mach text need to print?How much text do you need to print?
    【解决方案2】:

    看看这个页面Only allowing selection of one radio button in a form with PHP

    尝试按照该页面答案中的说明添加“for”属性。

    【讨论】:

      【解决方案3】:

      问题出在你的 php 代码中

      如下修改你的代码

      for($i=1;$i<=$number;$i++)
      {
          switch($_POST['b001']) {
              case "Last":
              {
                  echo "<input type=\"radio\" onclick=\"uncheck_radio(this)\" value=\"First\" name=\"h001\">" .$numberone; 
                  echo "<input type=\"radio\" onclick=\"uncheck_radio(this)\" value=\"Second\" name=\"h001\">".$numbertwo; 
                  echo "<input type=\"radio\" onclick=\"uncheck_radio(this)\" value=\"Third\" name=\"h001\">".$numberthree."</br>";
                  break;
              }}}
      

      名称前不要使用\"。

      【讨论】:

        猜你喜欢
        • 2013-06-22
        • 2011-02-04
        • 2015-03-11
        • 2013-10-07
        • 2017-04-04
        • 2016-07-11
        • 1970-01-01
        • 1970-01-01
        • 2013-08-01
        相关资源
        最近更新 更多