I’m updating a hidden field, #start, with two fields: a text field (that is used for time) and a datepicker field. However, when I select a date using datepicker and there is nothing in the time field, the hidden field is not updated. Also when the time field is filled in and I select a date via datepicker, the date is updated with the previous selection rather than the most recently selected date (probably due to the input value being updated). How can I write this function correctly? Thank you!
$("#datepicker").blur(function () {
var date = $(this).val();
var time = $('#time').val();
$("#start").val(date + time.toString(' HH:mm').toString());
});
Don’t use .blur(), use the datepicker’s onSelect event.
jsFiddle example
jQuery