Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /********* DATE SELECTOR ************
- // created by : Cahya DSN
- // create date : 2012-10-03
- *************************************/
- // default selisih tgl berangkat dgn hari pulang
- $selisih_hari=3;
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Date Selector</title>
- <style type="text/css">
- * {margin:0;padding:0;}
- body {font-family:verdana,sanf-serif;color:#009;font-size:10px;}
- select {background-color:#eee;border:solid 1px #999;font-family:verdana,sanf-serif;color:#009;font-size:10px;}
- .container {width:150px;padding:5px;margin:5px;}
- fieldset {padding:5px;margin:5px;}
- </style>
- </head>
- <body>
- <div class="container">
- <fieldset>
- <legend>Tanggal Berangkat</legend>
- <select name="day" id="day" size="1">
- <?php
- for($d=1;$d<=date("t");$d++){
- echo "<option value=\"$d\"".(date("d")==$d?" selected=\"selected\"":"").">".$d."</option>\n";
- }
- ?>
- </select>
- <select name="yearmonth" id="yearmonth" onChange="setDay('yearmonth','day');">
- <?php
- for($i=0;$i<12;$i++){
- $nextmonth = mktime(0, 0, 0, date("m")+$i, date("d"), date("Y"));
- echo "<option value=\"".date("Ym",$nextmonth)."\">".date("M Y",$nextmonth)."</option>";
- }
- ?>
- </select>
- </fieldset>
- <fieldset>
- <legend>Tanggal Pulang</legend>
- <select name="day1" id="day1" size="1">
- <?php
- for($d=1;$d<=date("t");$d++){
- echo "<option value=\"$d\"".(date("d",mktime(0,0,0,date("m"),date("d")+$selisih_hari,date("Y")))==$d?" selected=\"selected\"":"").">".$d."</option>\n";
- }
- ?>
- </select>
- <select name="yearmonth1" id="yearmonth1" onChange="setDay('yearmonth1','day1');">
- <?php
- for($i=0;$i<12;$i++){
- $nextmonth = mktime(0, 0, 0, date("m")+$i, date("d"), date("Y"));
- echo "<option value=\"".date("Ym",$nextmonth)."\">".date("M Y",$nextmonth)."</option>";
- }
- ?>
- </select>
- </fieldset>
- </div>
- <script>
- function setDay(id_ym,id_d) {
- var ym = document.getElementById(id_ym);
- var dy = document.getElementById(id_d);
- var dym = ym.options[ym.selectedIndex].value;
- var ddy = dy.options[dy.selectedIndex].value;
- var year=parseInt((dym.toString()).substr(0,4));
- var month=parseInt((dym.toString()).substr(4,2));
- var dd = new Date(year, month, 0);
- var days = dd.getDate();
- dy.options.length = 0;
- for (var i = 1; i <= days; i++)
- dy.options[dy.options.length] = new Option(i,i);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement