How to disable previous dates in ui date picker

I have a script like below:

<script>
  $(document).ready(function() {
      $("#sDate , #eDate").datepicker({
          dateFormat: 'yy-mm-dd',
          showOn: "button",
          buttonImage: "images/calendar.gif",
          buttonImageOnly: true
      });
  });

      

My html input fields are as follows:

<input type="text"  readonly name="scheduleStartDate" id="sDate" />
<input type="text"  readonly name="scheduleEndDate" id="eDate" />

      

When I click on the image, I get the ui calendar for input fields. Please help me turn off the previous dates in the calendar so that the user can select a start date from today onwards. Thank!

+3


source to share


2 answers


Use an attribute minDate

for your code like this

<script>
$(document).ready(function(){
    $( "#sDate , #eDate" ).datepicker({
        dateFormat: 'yy-mm-dd',
        showOn: "button",
        buttonImage: "images/calendar.gif",
        buttonImageOnly: true,
        minDate: new Date(2015, 6, 29)
    });
});
</script>

      



Where 2015 is the year, 6 is the month, and 29 is the date. Date before 06/29/2015 will be disabled.

Note. Assuming the datepicker used is the jQuery datepicker.

+1


source


Set minDate:0

to datepicker()

function



0


source







All Articles