Ramalingam Perumal
Ramalingam Perumal

Reputation: 1427

How to disable the specific date from Jquery UI datepicker

I want to disable the dates 20,21,25 OCT 2015. I am using the JQuery UI datepicker but i cannot getting output. Here is my sample code.It will help you.

<!doctype html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <title>jQuery UI Datepicker functionality</title>
      <link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
      <script src="http://code.jquery.com/jquery-1.10.2.js"></script>
      <script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

      <!-- Javascript -->
      <script>
        var unavailableDates = ["10/20/2015", "10/21/2015", "10/25/2015"]; 

            function unavailable(date) {
                dmy = date.getDate() + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
                if ($.inArray(dmy, unavailableDates) == -1) {
                    return [true, ""];
                } else {
                    return [false, "", "Unavailable"];
                }
            }

            $(function() {
                $("#iDate").datepicker({
                    dateFormat: 'dd MM yy',
                    beforeShowDay: unavailable
                });

            });
      </script>
   </head>
   <body>
      <!-- HTML --> 
      <p>Enter Date: <input type="text" id="datepicker-5"></p>
   </body>
</html>

Upvotes: 0

Views: 107

Answers (1)

Arun
Arun

Reputation: 1185

you can try this

d = $("#myDatepicker1").datepicker("getDate");
$("#myDatepicker2").datepicker("setDate", new Date(d.getFullYear()+1,d.getMonth(),d.getDate()));

Upvotes: 1

Related Questions