Reputation: 265
I have the following jQuery date and time pickers:
$('.timepicker').timepicker({
'minTime': '05:15',
'maxTime': '21:15',
'timeFormat': 'H:i',
'step': 15,
'forceRoundTime': true,
});
$('.datepicker').datetimepicker({
format: 'YYYY-MM-DD',
});
I want to change the time whenever the date is changed. I have tried the following different methods:
$('.datepicker').change(function() {
$('.timepicker').text('09:15')
})
$('.datepicker').change(function() {
$('.timepicker').setTime('09:15')
})
$('.timepicker').val('09:15')
And it still doesn't work.
Upvotes: 0
Views: 3773
Reputation: 218847
You appear to be using the wrong events/methods for your plugins. Plain HTML inputs do fine with change
and .val()
, but plugins often layer their own functionality on top of that. You should always use the API exposed by the plugins you're using rather than try to get at the underlying functionality directly.
For .datetimepicker()
are you using this library? If so, then the event you're looking for is dp.change
:
$('.datepicker').on('dp.change', function (e) {
// respond to the change event here
});
And for the time picker you're using, the method is .setTime()
. From their documentation in the link you provided:
$('#setTimeExample').timepicker('setTime', new Date());
The documentation linked doesn't readily identify if you can use a string to set the time as well, but you can certainly try:
$('.timepicker').timepicker('setTime', '09:15');
You can also look for additional documentation and examples for that plugin.
But basically when you're using complex plugins which overlay functionality on top of plain HTML elements, use the APIs provided by those plugins. You may very well be changing the value of the underlying HTML element, but the plugin might not notice that change if you're circumventing its API.
Upvotes: 1