If I want to display the JQUERY UI datepicker inline by attaching it to a DIV like $(\"div#someID\").datepicker()
- how do I access the chosen date? I assume if
$('div#someID').datepicker({
onSelect: function(dateText, inst) { alert(dateText); }
});
you must bind it to input element only
I needed to do this for a sales report that allows the user to choose a date range. The solution is similar to another answer, but I wanted to provide my example just to show you the practical real world use that I applied this to:
var reportHeader = `Product Sales History Report for ${$('#FromDate').val()} to ${$('#ToDate').val()}.` ;
```
You can also try this.
$('#datepickerID').val();
This is the simplest way.
You could do it as follows - with validation just to ensure that the datepicker is bound to the element.
var dt;
if ($("div#someID").is('.hasDatepicker')) {
dt = $("div#someID").datepicker('getDate');
}
see tag input example :
<div class="input-group date" data-target-input="nearest">
<input type="text" class="form-control datetimepicker-input form-control-sm" data-target="#dt_expdate" id="dt_expdate" />
<div class="input-group-append" data-target="#dt_expdate" data-toggle="datetimepicker">
<div class="input-group-text form-control-sm"><i class="fa fa-calendar"></i></div>
</div>
</div>
acess to get & assign value from
id="dt_expdate"
get value:
var date= $("#dt_expdate").val();
assign value:
$("#dt_expdate").val('20/08/2020');
You could remove the name attribute of this input, so it won't be submited.
To access the value of this controll:
$("div#someID").datepicker( "getDate" )
and your may have a look at the document in http://jqueryui.com/demos/datepicker/