excuse me want to ask. I'm sorry in advance if my language is not neat. how to get value datetimepicker from this form.
<div >
<label>Date:</label>
<div id="reservationdate" data-target-input="nearest">
<input type="text"
data-target="#reservationdate" />
<div data-target="#reservationdate" data-toggle="datetimepicker">
<div ><i ></i></div>
</div>
</div>
</div>
I managed to use the datetimepicker function and work but how to get value
$(function () {
$('#reservationdate').datetimepicker({
format: 'L',
});
});
CodePudding user response:
What you did here only initiates the datepicker on that element
$('#reservationdate').datetimepicker({
format: 'L',
});
You would have to listen for additional events to get the value based on the documentation.
Like this onChange example:
$('#reservationdate').datetimepicker({
format: 'L',
onChangeDateTime:function(dp, $input){
alert($input.val())
}
});
or after another event like a form submit or button click use this:
$('#reservationdate').datetimepicker('getValue');
CodePudding user response:
UPDATE:
Additionally, your html code is not correct.
You want to be setting the reservationdate
id on the input, not the div.
<div >
<label>Date:</label>
<div data-target-input="nearest">
<input type="text" id="reservationdate"
data-target="#reservationdate" />
<div data-target="#reservationdate" data-toggle="datetimepicker">
<div ><i ></i></div>
</div>
</div>
</div>
===========
You need to call the datepicker('getValue');
function.
For your example:
$('button.somebutton').on('click', function () {
var d = $('#reservationdate').datetimepicker('getValue');
console.log(d.getFullYear());
});
This returns a Date object which you can query the year, month, day or time.
Highly recommend you read through the entire documentation page - https://xdsoft.net/jqplugins/datetimepicker/. You might be able to find all these answers and more yourself.