-1

这是我的表格,它没有传递任何值。

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
 <html>
    <head>
        <style type="text/css">
            .welcome {
                color: #FFFFFF;
                text-align: center;
                background-color:red;
                font-weight:bold;
                height: 50px;
            }
        </style>
        <script type="text/javascript">
            function submitimg(myvalue)
            {
                document.getElementById('type').value = myvalue;
                document.getElementById('survey').submit(); 
            }
        </script>
    </head>
    <body>
        <table style="height: 232px; width: 500px">
            <form action="" method="post" name="survey" id="survey">
                <tr>
                    <td>
                        <div class="welcome"><br>Welcome!</div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <ul>
                            <br>
                            <br>
                            <div id="question1" style="display: inline;">
                                <h3>
                                    Are You 30+ Years Old?
                                </h3>
                                <div style="height: 10px">     </div>
                                <input type="button" name="age30" value="Yes" onclick="document.getElementById('question1').style.display='none';document.getElementById('question2').style.display='inline';">
                                <input type="button" name="age30" value="No" onclick="document.getElementById('question1').style.display='none';document.getElementById('question2').style.display='inline';">
                            </div>
                            <div id="question2" style="display: none;">
                                <h3>
                                    Are You Looking for a Date?
                                </h3>
                                <div style="height: 10px">     </div>
                                <input type="button" name="date" value="Yes" onclick="document.getElementById('question2').style.display='none';document.getElementById('question3').style.display='inline';">
                                <input type="button" name="date" value="No" onclick="document.getElementById('question2').style.display='none';document.getElementById('question3').style.display='inline';">
                            </div>
                            <div id="question3" style="display: none;">
                                <h3>
                                    Which Girl Is Your Type?
                                </h3>
                                <div style="height: 10px">     </div>
                                <input type="hidden" name="type" value="">
                                <img src="http://healthystartups.com/storage/600px-MA_Route_1.png?__SQUARESPACE_CACHEVERSION=1319542839834" width="100px" style="cursor:pointer;" onclick="submitimg('type1');">
                                <img src="http://jenntgrace.com/wp-content/uploads/2012/12/2.png" width="100px" style="cursor:pointer;" onclick="submitimg('type2');">
                                <img src="http://3.bp.blogspot.com/-Q_owQUxNjdQ/Te3ALCmT3oI/AAAAAAAAAnk/wv9r0b0MT-g/s1600/600px-MA_Route_3.svg_.jpg" width="100px" style="cursor:pointer;" onclick="submitimg('type3');">
                                <img src="http://4.bp.blogspot.com/-wY_qFr2pcAs/UCxhAayJ6oI/AAAAAAAAC6w/PgtLs2O_4g8/s1600/4.png" width="100px" style="cursor:pointer;" onclick="submitimg('type4');">
                            </div>
                        </ul>
                    </td>
                </tr>
            </form>
        </table>
    <?php
        $age30 = $_POST['age30'];
        $date = $_POST['date'];
        $type = $_POST['type'];
        echo $_POST['age30'];
    ?>
    </body>
 </html>
4

3 回答 3

1

您的 html 中有错误。名称应该是唯一的。在您的情况下,最好使用单选而不是按钮。

<input type="radio" name="age30" value="yes">
<input type="radio" name="age30" value="No" >


echo $_POST['age30'];

测试这段代码。

还将您的提交功能更改为此(Jquery 示例)

  $(function(){
            $(".submit_img").click(function (){
               $("#survey").submit(); // this line will submit form
            });
   });

现在,当您添加到元素“submit_img”类时,如果有人单击此元素,将提交 id=survey 的表单。

<img src="http://jenntgrace.com/wp-content/uploads/2012/12/2.png" width="100px" style="cursor:pointer;" class="submit_img">

演示

于 2013-06-24T08:23:48.953 回答
0

尝试像这样重命名输入

<input type="button" name="date[]" value="Yes">
<input type="button" name="date[]" value="No">
于 2013-06-24T08:27:44.440 回答
-1

请为您的表单指定一个操作。创建另一个 php 文件以获取 POST 变量并将该名称放入操作中。

于 2013-06-24T08:33:59.793 回答