1

I have a Jquery Calendar in html. It's display From and To date. following is my code:

html head section code:

<link rel="stylesheet" href="jquery/jquery.ui.all.css">
<script src="jquery/jquery-1.9.1.js"></script>
<script src="jquery/jquery.ui.core.js"></script>
<script src="jquery/jquery.ui.widget.js"></script>
<script src="jquery/jquery.ui.datepicker.js"></script>
<link rel="stylesheet" href="../demos.css">


<script>

$(function() {
    $( "#from" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#to" ).datepicker( "option", "minDate", selectedDate );


        }
    });
    $( "#to" ).datepicker({
        defaultDate: "+1w",
        changeMonth: true,
        numberOfMonths: 1,
        onClose: function( selectedDate ) {
            $( "#from" ).datepicker( "option", "maxDate", selectedDate );
        }
    });
});
</script>

html body code:

<label for="from">From</label>
<input type="text" id="from" name="from" class="tr"/>
<label for="to">to</label>
<input type="text" id="to" name="to" class="tr"/>

Well, it's working fine. But is it possible to disable the past month to the filed name from ? I just want user can't select previous month to the from field.

How the calendar is working Now : If user select From date i.e 18-05-2013 then To date start with 18-05-2013, If its 20-08-2013 then to date start with 20-08-2013.

Alex Mojum
  • 105
  • 2
  • 9

1 Answers1

2

You have to use the mindate parameter

$( "#from" ).datepicker({
    defaultDate: "+1w",
    changeMonth: true,
    numberOfMonths: 1,
    minDate: new Date(), // <-------- this will disable all dates prior to the date passed there.
    onClose: function( selectedDate ) {
        $( "#to" ).datepicker( "option", "minDate", selectedDate );


    }
});
fmsf
  • 36,317
  • 49
  • 147
  • 195