jQuery UI & Datepicker: Select a date range

This entry is part 4 of 14 in the series jQuery UI Datepicker

jQuery UI Datepicker – Select a Date Range

Select and define a date range.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Select a Date Range</title>
    <link rel='stylesheet' href='//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css'>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <script src='//code.jquery.com/ui/1.10.4/jquery-ui.js'></script>
    <link rel='stylesheet' href='http://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#from').datepicker({
                defaultDate: '+1w',
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function (selectedDate) {
                    $('#to').datepicker('option', 'minDate', selectedDate);
                }
            });
            $('#to').datepicker({
                defaultDate: '+1w',
                changeMonth: true,
                numberOfMonths: 3,
                onClose: function (selectedDate) {
                    $('#from').datepicker('option', 'maxDate', selectedDate);
                }
            });
        });
    </script>
</head>
<body>

<label for='from'>From</label>
<input type='text' id='from' name='from'>
<label for='to'>to</label>
<input type='text' id='to' name='to'>

</body>
</html>
Try The Code

The defaultDate: ‘+1w’ will highlight a day 7 days from the current date.

Datepicker Widgets API Doc
Series Navigation<< jQuery UI & Datepicker: Datepicker with animations
jQuery UI & Datepicker: Dates in other months >>

Leave a comment

Leave a Reply