dimanche 22 mars 2015

jQuery datetimepicker - how to get date in javascript?


So I have a jQuery DateTimePicker v2.4.1 attached on a text input. I wanted to make it so then when the user clicks and changes the Month or Year of the picker - it would update the date within the form as this doesn't seem to be a default behavior of the plugin.



$(timepicker).datetimepicker({
format: "d M Y h:i A",
step: 15,
validateOnBlur: false, //use ValidateDateTime.js instead of jquery default
closeOnInput: true,
closeOnDateSelect: true,
onClose: function() {
var validatedDate = validateDate($(timepicker).val());
if (validatedDate != false) {
$(timepicker).val(validatedDate);
}
},
changeMonth: true,
changeYear: true,
onChangeMonth: function() {
//pop name of month into field and update calendar
var d = $(this).datetimepicker('getDate');
console.log(d + this.html());

/*
$(timepicker).datetimepicker.trigger("select.xdsoft", [d]);
*/
}
});


A problem that occurs is: var d = $(this).datetimepicker('getDate'); does not actually retrieve the date and just returns the datetimepicker element.


How do I get the date in js or more specifically - how could I force an update when the user clicks on a month within the drop down.





Aucun commentaire:

Enregistrer un commentaire