date selection box with javascript

<div style="display: inline-block">
  <fieldset>
    <legend>Date</legend>
    <select id="day" name="day"></select>
    <select id="month" name="month"></select>
    <select id="year" name="year"></select>
  </fieldset>
</div>

<script type="text/javascript">
for ( i = 1; i <= 31; i++ ) 
  document.getElementById("day").innerHTML += '<option value=' + i + '>' + i + '</option>';
for ( i = 1; i <= 12; i++ )
   if ( i == ( new Date() ).getMonth() + 1 ) document.getElementById("month").innerHTML += '<option value=' + i + ' selected>' + i + '</option>' 
   else document.getElementById("month").innerHTML += '<option value=' + i + '>' + i + '</option>';
for ( i = 1970; i <= (new Date()).getFullYear(); i++ )
  if ( i == (new Date()).getFullYear() ) document.getElementById("year").innerHTML += '<option value=' + i + ' selected>' + i + '</option>'
  else document.getElementById("year").innerHTML += '<option value=' + i + '>' + i + '</option>';
</script>
Advertisements