提交表格后保留下拉值

时间:2013-10-05 07:27:23

标签: php

以下是我的代码和结构。问题是提交表单时我无法保留下拉框的值。可以请一些人突出我哪里出错了?或者,如果有更好的方法来处理这个,请建议。谢谢。

注意:我尝试在上面的代码中仅将一个下拉列表应用于上面,但我会将这些内容扩展到两个下拉列表中。

代码:

<!doctype html>
<html>
<head></head>
<body>
        <form name="form1" method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" id="form1">
        <div>
            <div="pickYear">
            <select name="yearPickNow">
            <option value='selectyear'<?php echo isset($_GET["yearPickNow"]) && $_GET["yearPickNow"] == "selectyear" ? "selected" : "" ?>>Year</option>
            <option value="2014" <?php if($_POST['yearPickNow'] == '2014') {echo "selected='selected'"; } ?> >2014</option>
            <option value='2015'<?php echo isset($_GET["yearPickNow"]) && $_GET["yearPickNow"] == "2015" ? "selected" : "2015" ?>>2015</option>
            <option value='2016'<?php echo isset($_GET["yearPickNow"]) && $_GET["yearPickNow"] == "2016" ? "selected" : "2016" ?>>2016</option>
            <option value='2017'<?php echo isset($_GET["yearPickNow"]) && $_GET["yearPickNow"] == "2017" ? "selected" : "2017" ?>>2017</option>
            </select>
            </div>

            <div id="pickMonth">
            <select name="monthPickNow" id="monthPickNow" onChange="document.forms['form1'].submit()">
            <option value='selectmonth'>Month</option>
            <option value='January'>January</option>
            <option value='February'>February</option>
            <option value='March'>March</option>
            </select>
            </div>
        </div>

        <?php
        //some php code to bring up and display content relevant to the selected year and month from a SQL database
        ?>
        </form>
</body>

0 个答案:

没有答案