Reputation: 11117
So i have this input field, when i use Keith Wood calendar and pick a date it doesn't trigger any changes that jquery can detect (change or keyup or input).
<input type="text" name="new_post_date" id="date" required>
<script>
$(document).ready(function () {
$('#date').calendarsPicker({ dateFormat: 'yyyy-mm-dd' });
$('#date').on("input", function(e){
var today = new Date();
var time = today.format("H:M:s");
$('#date').val($('#date').val() + ' ' + time);
});
});
</script>
I need to see if user has picked a date so that i can append time to it. if i pick a date and then enter some value (a number for example) it executes the function but it should do it without the need for another extra input after picking date.
at the moment when user picks a date it doesn't execute:
$('#date').on("input", function(e){
var today = new Date();
var time = today.format("H:M:s");
$('#date').val($('#date').val() + ' ' + time);
});
How do i make this work?
Upvotes: 2
Views: 65
Reputation: 73896
You can use calendarsPicker onSelect
event like this:
$('#date').calendarsPicker({
dateFormat: 'yyyy-mm-dd',
onSelect: function (dates) {
alert('The chosen date(s): ' + dates);
var today = new Date();
var time = today.format("H:M:s");
$('#date').val(dates + ' ' + time);
}
});
Upvotes: 1