Reputation: 123
I have following code to show me the selected day from datepicker:
<input onFocus="blur();" class="day_selected">
I have this and the datepicker running multiple times in same page and once the page is reloaded using jquery the input is still there, but no date showing. In order to show, I have to click on date again on the datepicker and then it shows.
How can I make sure that today's date ALWAYS shows no matter what.
Upvotes: 1
Views: 359
Reputation: 337560
To set the default value of the field to the current date, try this:
var currentDate = new Date();
var prettyDate = (currentDate.getMonth() +1) + '/' + currentDate.getDate() + '/' + currentDate.getFullYear();
$(".day_selected").val(prettyDate);
Obviously, if the user selects a different date in the control and then refreshes the date will be reset to today. If you need it to maintain state, you'll either need to store the value in a cookie, or send it to a back-end datastore via AJAX.
Upvotes: 1