I am having an issue with the JQuery datepicker and the forward and back buttons in the browser.
I have two text fields, one that is a “date” field and one field that is just a regular text input. On page load, I initialize the datepicker with the following code:
$(document).ready(function() {
$('#date').datepicker()
$('#date').datepicker("setDate",new Date())
});
The page shows up fine, and the datepicker has the correct date in it. Everthing works as intended, but if I press the browser’s back button, and then the forward button (bringing me back to the same page) the text field that was empty is now filled in with what was in the datepicker box.
For reference, here is the relevant html snippet
<body>
<p>
Here I will have two text boxes, one datepicker and one regular
</p>
<input type="text" id="notdate"/>
<input type="text" id="date"/>
</body>
Goal:
I need the date box to show up with the date already there, as text and I want to get rid of the input duplication on forward/back reloads of the page.
Note: if you change the other text box before pressing back/forward everything is fine. Hopefully there is a less hacky way to fix it than to touch all of the boxes as the page is loaded. =]
A correct workaround was provided by Julian. Giving the text fields name attributes seemed to clear up the problem. Not sure why this works considering divs are identical, but it did solve the problem.