Sha
Sha

Reputation: 506

How to disable previous dates in ui date picker

I have script as 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 image, I'm getting the ui calender for input fields, Please help me to disable previous dates in the calender so that the user can only select the start date from today's date and onwards. Thank you!

Upvotes: 3

Views: 73

Answers (2)

Tatha
Tatha

Reputation: 137

Use minDate attribute to 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. The date before 29/06/2015 will be disabled.

Note: Assuming the datepicker you've used is jQuery datepicker.

Upvotes: 1

Sa Si Kumar
Sa Si Kumar

Reputation: 662

Set minDate:0 in datepicker() function

Upvotes: 0

Related Questions