1
votes
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Datepicker - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css">

    <script>
        $(function () {
            $("#datepicker1").datepicker();
        });
    </script>

    <script>
        $(function () {
            $("#datepicker2").datepicker();
        });
    </script>
</head>
<body>
    <p>Date 1: <input type="text" id="datepicker1"></p>
    <p>Date 2: <input type="text" id="datepicker2"></p>
</body>
</html>

There are two date pickers in my code here. What I want is to disable dates when I select a date from the first date picker. That is suppose if I select date like 15/01/2015 from the first date picker. Now in the second date picker all the dates after 15/01/2015 will be disabled. But the dates before 15/01/2015 will be enabled in the second date picker.

How can I do that?

2

2 Answers

2
votes

You can use the maxDate option

$(function () {
    $("#datepicker1").datepicker().change(function () {
        $("#datepicker2").datepicker('option', 'maxDate', $(this).datepicker('getDate'));
    });
    $("#datepicker2").datepicker();
});

Demo: Fiddle

0
votes

onSelect event fires when you select a date from DatePicker.

Try the following code.

$(function () {
    $("#datepicker1").datepicker({
        onSelect: function (date) {
            $("#datepicker2").datepicker({
                'maxDate': date
                //'minDate' : date
            });
        }
    });
});

You can manipulate the dates using maxDate and minDate properties.