I have a simple form for generating reports that I am adding a jqueryUI datepicker to. The problem I am having is when I try to repopulate the fields with the info from the user.
Jquery seems to be resetting the default value on my date fields (currently, it picks 2 different dates in July). How can I set it back to the user submitted value?
My current code:
<form method="post" action="">
Username: <input type="text" size="12" name="username" required value="foo" />
Password: <input type="password" size="12" name="password" required value="bar" />
Start Date: <input id="startdate" type="text" size="12" name="startday" required value="06/28/2012" />
End Date: <input id="enddate" type="text" size="12" name="endday" required value="06/30/2012" />
<script type="text/javascript">
$(function(){
$("#startdate").datepicker();
$("#enddate").datepicker();
});
</script>
<input type="submit">
</form>
Set the date to highlight on first opening if the field is blank. Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (e.g. +7) or a string of values and periods (‘y’ for years, ‘m’ for months, ‘w’ for weeks, ‘d’ for days, e.g. ‘+1m +7d’), or null for today.
Initialize a datepicker with the defaultDate option specified.
Get or set the defaultDate option, after init.
http://jqueryui.com/demos/datepicker/#option-defaultDate
Fiddle:
http://jsfiddle.net/iambriansreed/gMNrZ/