HTML表单不提交值

时间:2013-06-24 08:19:57

标签: php html forms

这是我的表单,并没有传递任何值。

 <!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>

3 个答案:

答案 0 :(得分: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
            });
   });

现在当你添加到元素&#39; submit_img&#39; class,如果有人点击此元素,将提交id = survey的表单。

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

<强> DEMO

答案 1 :(得分:0)

尝试重命名输入

<input type="button" name="date[]" value="Yes">
<input type="button" name="date[]" value="No">

答案 2 :(得分:-1)

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