jQuery datepicker with disable date except range

jQuery ui datepicker

Webcontrol is used to select a date from a popup or inline calendar.

jQuery datepicker code to display and disable date ranges

Popup datepicker with disabled date selection before start date and after end date when click on calendar image .

  $( function() {
    $( "#datepicker" ).datepicker({
      showOn: "button",
      buttonImage: "images/calendar.gif",
      buttonImageOnly: true,
      buttonText: "Select date",
      dateFormat: "dd-mm-yy",
beforeShowDay: function (date) {
                var startDate = new Date("2016-02-28"); 
                endDate = new Date("2016-04-12"); 
                return [date>=startDate && date<=endDate];
            }

    }).datepicker("setDate", $('#date_today').text().trim());
});

beforeShowDay

beforeShowDay attribute is used to invoke a function that takes a date as a parameter and must return an array with index 0, 1 and 2.

Array index purposes:

[0]: can be either true or false and indicating whether or not this date is disabled.

[1]: a CSS class name to add to the date's cell or "" for default style.

[2]: popup tooltip for this date.

beforeShowDay: function (date) {
                var startDate = new Date("2016-02-28"); 
                endDate = new Date("2016-04-12"); 
                return [date>=startDate && date<=endDate];
            }

here array [0] disables the date if not in the required range.


jQuery Example Code - To disable date except range and Setting default selected date

Provides option to select the date between start and end date, preventing the date selection except provided date range.

Also highlights the default selected date.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
      <script type = "text/javascript">
   $( function() {
    $( "#datepicker" ).datepicker({
      showOn: "button",
      buttonImage: "calendar.gif",
      buttonImageOnly: true,
      buttonText: "Select date",
      dateFormat: "dd-mm-yy",
beforeShowDay: function (date) {
                var startDate = new Date("2016-03-02"); 
                endDate = new Date("2016-03-12"); 
                return [date>=startDate && date<=endDate];
            }

    }).datepicker("setDate", new Date("2016-03-08"));
});

      </script>		
   </head>	
   <body>
   <p>Test Section</p>
<div>
<p>Date: <input type="text" id="datepicker" name="datepicker"></p
</div>
   </body>
</html>
Output:
jquery datepicker disable date code output
Java Programming Language Examples

GCD and Rational Number Java Program

Java Queue Program using exception

Java Stack Program using exception

Addition of three integers java program

Biggest of three integers java program

Fibonacci numbers java program

Arithmetic Operations Menu java program

Second Smallest Element In Array Java Program

Transpose Of A Matrix Java Program

Java Program to Display triangle of stars (*)

Java Programming Prints Product Tables

Java Program to Display triangle of numbers

Java Programming Gets Current Date

Java Programming Finds Character Vowel or Consonent

Java Programming HCF and LCM Computation

Java Programming Sum of Command Line Integer Arguments

Java Programming Multiplication of Command Line Integer Arguments

Java Programming Multiplication of Command Line Floating Point Numeric Arguments

Java Programming String Contains or Not

Java Programming Gets Grade Description using Switch

Java Programming CSV File Reader

Java Programming Character Frequency Count in String using for each

Java Programming Finds Min from Integer Array by Passing Array to Method

Java Programming Linear Search

Java Programming Binary Search

Java Programming Ternary Search

Java Programming Generates Range of Numbers

Java Programming Generates Range of Characters

Java Programming Computes Square Root Value

Java Programming Checks Number is Positive or Negative

Java Programming Checks Number is Odd or Even

Java Programming Computes Plot Area

Java Programming Convert Number of Days into Years

Java Programming Checks a Year is Leap Year, Century Year or Not

Java Programming Checks a Character is Digit, Letter or neither digit nor letter

Java Programming Checks a Number is Palindrome or not

Java Programming Sum of Two Matrix

Java Programming Power Computation

Java Programming Checks Number is an Armstrong Number or not

Java Programming Temperature Unit Conversions

Java Programming Generates Random Numbers in Specified Range

Java Programming Computes Sum of Digits and Product of Digits

Java Programming Computes Reverse Number

Java Programming Computes Factorial Value

Java Programming Checks Prime Number or not

Java Programming Computes Harmonic Series

Java Programming Generates Floyd's Triangle

Java Programming Reverses String

Java Programming Checks Palindrome String or not

Java Programming Opens Notepad

Java Programming Searches String using RegEx Pattern

Java Programming Searches Word in String

Java Programming Gets System Environment Variables

Java Programming Gets IP Address of Server Name

Java Programming Arrays Sort and Reverse using sort method

Java Programming Bubble Sorting

Java Programming Selection Sorting

Java Programming Insertion Sorting

Java Programming Merge Sorting

Java Programming Quick Sorting

Java Programming Counting Sort

Java Programming Radix Sorting

Java Programming Sorting Array of Strings

Java Programming String Characters Sorting

Java Programming Sum of First N Numbers

Java Programming Product of First N Numbers

Python installation

Privacy Policy  |  Copyright@2017 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^