开发者

how to auto change date in dropdown menu with AJAX or javascript

first of all I'm trying to have the dropdown menu send input value to the form.php and the dropdown menu is on the index.php

I have this drop down menu

<select name="date" id="date" style="width:100px;" onchange="availablePeriodOfDay(this)">
    <option value="2011-08-21" >2011-08-21</option>
    <option value="2011-08-20" >2011-08-20</option>
    <option value="2011-08-19" >2011-08-19</option>
    <option value="2011-08-18" >2011-08-18</option>
    <option value="2011-08-17" >2011-08-17</option>
    <option value="2011-08-16" >2011-08-16</option>
    <option value="2011-08-15" >2011-08-15</option>
    <option value="2011-08-14" >2011-08-14</option>
</select>

this one is going back 8 days from the current da开发者_StackOverflow社区y but if I want it to change the date automatic if the date changed to tomorrow 2011-08-22 and make the rest also change everytime automatically

will that be possible to do so?


I think what you want to do there is generate it in PHP when the page is loaded - do you want something like this?

<?php

  $numDaysToShow = 8;
  $_1day = 60 * 60 * 24; // 1 day in seconds (=86400)
  $start = time();
  $end = $start - ($_1day * $numDaysToShow); // 8 days ago
  $theSelect = "<select name=\"date\" id=\"date\" style=\"width:100px;\" onchange=\"availablePeriodOfDay(this)\">";
  for ($i = $start; $i > $end; $i -= $_1day) $theSelect .= "\n  <option value=\"".date('Ymd',$i)."\">".date('Y-m-d',$i)."</option>";
  $theSelect .= "\n</select>";

  print($theSelect);

?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜