I have two datepickers named startdate and enddate. I want to disable all other dates except the selected date from startdate. for example if i selected 15/12/2016 from startdate datepicker then i want to disable all other dates in enddate datepicker except 15th day.
Demofiddle : https://jsfiddle.net/d7vzxn8s/
This is my code :
<p>Start Date: <input type="text" id="startdate"></p>
<p>End Date: <input type="text" id="enddate"></p>
<script>
$("#startdate").datepicker({
onSelect: function (selected) {
var dt = new Date(selected);
dt.setDate(dt.getDate());
$("#enddate").datepicker("option", "minDate", dt);
}
});
$("#enddate").datepicker();
Modified Fiddle : https://jsfiddle.net/d7vzxn8s/2/
var dateToday = new Date();
var selectedDate;
$("#startdate").datepicker({
minDate: dateToday,
onSelect: function (dateText, inst) {
selectedDate = $(this).datepicker( "getDate" );
var slctdDate = selectedDate.getDate()
// alert(selectedDate);
$("#enddate").datepicker({
minDate: inst.day,
beforeShowDay: function(date){
//Only allow fri, sat
return [date.getDate()==slctdDate];
}
});
}
});
$("#enddate").datepicker("option");
If you want to make only one option to pick in the "enddate
" selector, it is oblivous that "enddate
" would equal to "startdate
".
That's why you can simply copy value from "startdate
" as you pick it to the "enddate
" selector and disable "enddate" to be changed at all.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With