Advertisement
cdsatrian

date selector

Oct 2nd, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.36 KB | None | 0 0
  1. <?php
  2. /********* DATE SELECTOR ************
  3. //  created by  : Cahya DSN
  4. //  create date : 2012-10-03
  5. *************************************/
  6. // default selisih tgl berangkat dgn hari pulang
  7. $selisih_hari=3;
  8. ?>
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12.   <title>Date Selector</title>
  13.   <style type="text/css">
  14.     * {margin:0;padding:0;}
  15.     body {font-family:verdana,sanf-serif;color:#009;font-size:10px;}
  16.     select {background-color:#eee;border:solid 1px #999;font-family:verdana,sanf-serif;color:#009;font-size:10px;}
  17.     .container {width:150px;padding:5px;margin:5px;}
  18.     fieldset {padding:5px;margin:5px;}
  19.   </style>
  20. </head>
  21. <body>
  22. <div class="container">
  23. <fieldset>
  24. <legend>Tanggal Berangkat</legend>
  25. <select name="day" id="day" size="1">
  26. <?php
  27.   for($d=1;$d<=date("t");$d++){
  28.     echo "<option value=\"$d\"".(date("d")==$d?" selected=\"selected\"":"").">".$d."</option>\n";
  29.   }
  30. ?>
  31. </select>
  32. <select name="yearmonth" id="yearmonth" onChange="setDay('yearmonth','day');">
  33. <?php  
  34. for($i=0;$i<12;$i++){
  35.   $nextmonth = mktime(0, 0, 0, date("m")+$i, date("d"),   date("Y"));
  36.   echo "<option value=\"".date("Ym",$nextmonth)."\">".date("M Y",$nextmonth)."</option>";
  37. }
  38. ?>
  39. </select>
  40. </fieldset>
  41. <fieldset>
  42. <legend>Tanggal Pulang</legend>
  43. <select name="day1" id="day1" size="1">
  44. <?php
  45.   for($d=1;$d<=date("t");$d++){
  46.     echo "<option value=\"$d\"".(date("d",mktime(0,0,0,date("m"),date("d")+$selisih_hari,date("Y")))==$d?" selected=\"selected\"":"").">".$d."</option>\n";
  47.   }
  48. ?>
  49. </select>
  50. <select name="yearmonth1" id="yearmonth1" onChange="setDay('yearmonth1','day1');">
  51. <?php  
  52. for($i=0;$i<12;$i++){
  53.   $nextmonth = mktime(0, 0, 0, date("m")+$i, date("d"),   date("Y"));
  54.   echo "<option value=\"".date("Ym",$nextmonth)."\">".date("M Y",$nextmonth)."</option>";
  55. }
  56. ?>
  57. </select>
  58. </fieldset>
  59. </div>
  60. <script>
  61.   function setDay(id_ym,id_d) {
  62.     var ym = document.getElementById(id_ym);
  63.     var dy = document.getElementById(id_d);
  64.     var dym = ym.options[ym.selectedIndex].value;
  65.     var ddy = dy.options[dy.selectedIndex].value;
  66.     var year=parseInt((dym.toString()).substr(0,4));
  67.     var month=parseInt((dym.toString()).substr(4,2));
  68.     var dd = new Date(year, month, 0);
  69.     var days = dd.getDate();
  70.     dy.options.length = 0;
  71.     for (var i = 1; i <= days; i++)
  72.       dy.options[dy.options.length] = new Option(i,i);
  73.    
  74.   }
  75. </script>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement