douzhengyi5022 2013-04-06 22:01
浏览 8
已采纳

复选框始终只显示“打开”

this is how I have 2 checkbox and I do not want that you should only click on them simultaneously. it must only be possible to click on one at a time!. in the present to when I clicked the news, so it must enter a number in there to write "on". I would like to later be sure it is entered into the database.

the problem is that it appears to say "on" no matter what!?

<form action="#" method="post">
                    <table>
                        <tr>
                            <td>Emne</td>
                            <td>Vigtigt: <input type="checkbox" name="vigtigt" class="new"> Nyhede: <input type="checkbox" name="nyhede" class="new"></td>
                        </tr>
                        <tr>
                            <td>Title</td>
                            <td><input type="text" name="title" maxlength="50" class="new"></td>
                        </tr>
                        <tr>
                            <td>Tekst</td>
                            <td><textarea name="tekst" cols="20" rows="15" class="new"></textarea></td>
                        </tr>
                        <tr>
                            <td><input type="submit" name="opret" value="Opret Blog" class="new"></td>
                            <td></td>
                        </tr>
                    </table>
                    <?php
                    if(isset($_POST["opret"]))
                    {
                        if($_POST["vigtigt"] != "")
                        {
                            echo $_POST["vigtigt"];
                            echo "<br />";
                            echo $_POST["nyhede"];
                        }
                        elseif ($_POST["nyhede"] != "")
                        {
                            echo $_POST["vigtigt"];
                            echo "<br />";
                            echo $_POST["nyhede"];
                        }
                        else
                        {
                            echo "Fejl!";   
                        }
                    }
                    ?>
                </form>
  • 写回答

2条回答 默认 最新

  • dpsu84620 2013-04-06 22:03
    关注

    You have to define a value attribute for it to:

     <input type="checkbox" name="vigtigt" class="new" value="MyValueHere">
    

    This way you will receive its value when its checked.

    Edit:

    To have only one selected at a time you will have to use type="radio" and give them the same name and different values.

    <input type="radio" name="vigtigt" class="new" value="MyValueHere">
    <input type="radio" name="vigtigt" class="new" value="MyOtherValueHere">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘