How To Set Datepicker Value To Selected Date After Page Load?
I have one datepicker having id='from_dt' and button with id='fromToDate'. When i select a date from the datepicker and click the button, the page will load and then i want to set
Solution 1:
In the documentation of jquery UI datepicker it says: $( ".selector" ).datepicker( "setDate", "10/12/2012" );
See: Documentation
Solution 2:
If you post your date then it will fetch by using $_POST
var $date = isset($_POST["date"])?$_POST["date"]:"";
<input value="$date" class="form-control"id="from_dt"type="text" placeholder="From Date" value=""readonly>
^^^^^^^^^^^^^^
Solution 3:
functiongetEventListWithDateTime() {
$("#eventListDatePickerForm").attr( "action", "/eventList/" + $("#from_dt").val() + "/" + $("#to_dt").val());
}
This is my function on button click event
Solution 4:
Try a workaround for this, put your date value in hidden input field in onchange
event of date field,
$('#from_dt').change(function(){
var fromDate = $(this).val();
$('#fromDate').val(fromDate);
}
<input type="hidden" id="fromDate">
And in $(document).ready()
if($('#fromDate').val() !== undefined || $('#fromDate').val() != '') {
$(this).val($('#from_dt').val());
}
Solution 5:
Mike's answer helped me https://stackoverflow.com/a/28061283/6517383
For using a dynamic variable just use:
var dateToBePrefilled = "10/12/2012";
$( ".selector" ).datepicker( "setDate", dateToBePrefilled );
Post a Comment for "How To Set Datepicker Value To Selected Date After Page Load?"