drb56625 2011-11-20 17:47
浏览 30

创建php表单,根据用户选择显示消息

I want to create a php form with checkbox, like this:

< form method="post>
        <input type="checkbox" name="formpractise[]" value="A" /> <br/>
        <br/>
        <input type="checkbox" name="formpractise[]" value="B" /> <br/>
        <br/>
        <input type="checkbox" name="formpractise[]" value="C" />  <br/>
        <br/>
        <input type="checkbox" name="formpractise[]" value="D" /> <br/>
        <br/>
        <input type="checkbox" name="formpractise[]" value="E" /> <br/>
        <br/>
        <input type="checkbox" name="formpractise[]" value="F" /> <br/>
        <br/>
        <input type="submit" name="formsubmit" value="Submit" />
</form>

when the user select checkbox I want to print a message according user choice. Not the choice he made, a message depending his choice.

  • 写回答

4条回答 默认 最新

  • doufeixi6014 2011-11-20 17:53
    关注

    If you are using the jQuery library, the Javascript would look something like this:

    $(function(){
        // The messages
        var messages = {
            A  : "Message for A",
            B  : "Message for B",
            C  : "Message for C",
            D  : "Message for D",
            E  : "Message for E",
            F  : "Message for F"
        };
        $("input").click(function(){
            var key = $(this).val();
            // Only if the checkbox is checked
            if( $(this).is(":checked") )
            {
                // Alert the message
                alert(messages[key]);
    
                // Fill the HTML of the div with the id messageDIVID
                $("#messageDIVID").html(messages[key]);
            }
        });
    });
    

    If you have all your messages inside your PHP code. And you have an array, you can do this

    $messages = Array("A" => "Message for A", 
                      "B" => "Message for B", 
                      "C" => "Message for C", 
                      "D" => "Message for D", 
                      "E" => "Message for E", 
                      "F" => "Message for F");
    
    echo "var messages = " . json_encode($messages) . ";";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比