I have two date fields in HTML form. If I Select a date in first field, the second field should show date greater than the first field in date picker. Here are my Date Picker code:
$(document).on('focus', '.dt', function() {
$(this).datepicker({ dateFormat : 'dd-mm-yy'});
});
And here is my form having two fields:
<td width="212">
<input type="date" class="dt" name="s_invoice_date_draft1"
value="<?php echo @$_REQUEST['s_invoice_date_draft1']; ?>">
To
<input type="date" class="dt" name="s_invoice_date_draft2"
value="<?php echo @$_REQUEST['s_invoice_date_draft2']; ?>">
</td>
Need solution in JavaScript.
Say you have two inputs inp_begintime
and inp_endtime
, then just initialize the date picker in this way, here when you will change the date of inp_begintime
it will set minDate
for inp_endtime
and if you set date in inp_endtime
it will set maxDate
for inp_begintime
.
$("#inp_begintime").datepicker({
dateFormat : 'dd-mm-yy',
onSelect: function(selected) {
$("#inp_endtime").datepicker("option","minDate", selected)
}
});
$("#inp_endtime").datepicker({
dateFormat : 'dd-mm-yy',
onSelect: function(selected) {
$("#inp_begintime").datepicker("option","maxDate", selected)
}
});