I am using this script to automatically set the current date on a form... However, when I post the form, it is actually putting the Day +1 into the database (the year and month are correct). So for example if I set the date to June 8, 2011 on the form, it will post into the db as 2011-06-09. I am not sure whats going on...
Also, if the form has a missing input field (and the form reloads), the date resets back to the current date, instead of retaining the php-printed date values.
In the head, I have:
<script>
var monthtext=['January','February','March','April','May','June','July','August','September','October','November','December'];
function populatedropdown(dayfield, monthfield, yearfield){
var today=new Date()
var dayfield=document.getElementById(dayfield)
var monthfield=document.getElementById(monthfield)
var yearfield=document.getElementById(yearfield)
for (var d=1; d<32; d++)
dayfield.options[d]=new Option(d, d+1)
dayfield.options[today.getDate()]=new Option(today.getDate(), today.getDate(), true, true) //select today's day
for (var m=0; m<12; m++)
monthfield.options[m]=new Option(monthtext[m], monthtext[m])
monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) //select today's month
var thisyear=today.getFullYear()
for (var y=0; y<4; y++){
yearfield.options[y]=new Option(thisyear, thisyear)
thisyear-=1
}
yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true) //select today's year
}
</script>
In the form I have:
<script type="text/javascript">
//populatedropdown(id_of_day_select, id_of_month_select, id_of_year_select)
window.onload=function(){
populatedropdown("daydropdown", "monthdropdown", "yeardropdown")
}
</script>
<tr>
<td>
<select name="Month" id="monthdropdown">
<option value="<?php print "$Month"; ?>"><?php print "$Month"; ?></option>
</select>
<select name="Day" id="daydropdown">
<option value="<?php print "$Day"; ?>"><?php print "$Day"; ?></option>
</select>
<select name="Year" id="yeardropdown">
<option value="<?php print "$Year"; ?>"><?php print "$Year"; ?></option>
</select>
</td>
</tr>