O'Reilly logo

jQuery UI Cookbook by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Restricting the date range

Your application may need to restrict allowable date selections for limiting the date range. Perhaps this is predicated on some other condition being true or event being triggered. Thankfully, we have enough flexibility to handle the most common selection-restricted configurations of the widget.

Getting ready...

We'll use the basic input element markup for our datepicker widget:

<div>
    <label for="start">Start:</label>
    <input id="start" type="text" size="30"/>
</div>

How to do it...

We'll create our datepicker widget as follows, using the minDate and maxDate options.

$(function() {

    $( "input" ).datepicker({
        minDate: new Date(),
        maxDate: 14
    });

});

When we activate the datepicker widget by clicking on the input field, you'll ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required