doujuanxun7167 2015-10-08 17:18
浏览 55
已采纳

进行默认日期选择2012年4月

The earliest record I'm searching is from 4/2012 so I'd like the default selection when the page is first loaded to be that. 2012 is the first entry in option list, it's making April appear first that is the issue

Here's my current php code for two select boxes, one for month and one for year.

    <form class="formtext" action="monthly_sums.php" method="get">
    <p>Monthly Report<br></p>
        Company:
            <select class="bck1" name="company" id="company">
                <?php echo $options ?>
            </select><br>
        Month:
            <select class="bck1" name="month" id="month" onchange="" size="1">
                <option value="01">January</option>
                <option value="02">February</option>
                <option value="03">March</option>
                <option value="04">April</option>
                <option value="05">May</option>
                <option value="06">June</option>
                <option value="07">July</option>
                <option value="08">August</option>
                <option value="09">September</option>
                <option value="10">October</option>
                <option value="11">November</option>
                <option value="12">December</option>
            </select>
        Year: 
            <select class="bck1" name="year" id="year" onchange="" size="1">
                <?php echo $options2 ?>
            </select>
        <input type="submit" class="submit" onClick="return monthlyValidation()"/>
    </form>

and here's my php for the year option list:

    //propagate year selection range for monthly report. from 2012 to current year
    $curr_year=date("Y");
    for($i=2012;$i<=$curr_year;$i++)
    {
        $options2 .= "<option value =\"".$i."\">".$i."</option>";
    }

thanks in advance!

  • 写回答

1条回答 默认 最新

  • dongtanjian9310 2015-10-08 17:23
    关注

    You could use the selected="selected" attribute on the 'April'-<option> to make April selected on loading the page. Or use a JavaScript init function to set the correct option as selected.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 有没有帮写代码做实验仿真的
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题