2
votes

The default date for jQuery's datepicker is the current date, but I need it to be the pre-populated date from my #start_date input field.

This is where I'm at now but it doesn't work.

var start_date = $('#start_date').val();
$('.datepicker').datepicker("option", "defaultDate", start_date);
<input type="text" id="start_date" name="start_date" class="datepicker form-control col-sm-6" placeholder="Start" value="<?php (!empty($row['start_date'])?$row['start_date']:'');?>>
2
The default date for jQuery's datepicker is the current date this is not the case. Assuming the value of the input field is in a format which can be parsed as a Date() that is what will be used as the default value. If it isn't a valid Date(), then it defaults to today. - Rory McCrossan
What is the value of $row['start_date']? - Barmar

2 Answers

1
votes

try:

var start_date = $('#start_date').val();
$('.datepicker').datepicker("option", "defaultDate", new Date(start_date));
-1
votes

if the input field date is the same format which set in the input field when you pick the date, then it will be loaded by Datepicker by default without any javascript code just Datepicker intalization.

may be your variable $row['start_date'] show date and time in input field try to make the value in the format of mm/dd/yyyy and it should work perfectly.