jQuery UI & Datepicker: Basic datepicker

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

jQuery UI Datepicker – Default functionality

The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay.

Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close.

If a date is chosen, feedback is shown as the input’s value.

<!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.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='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#datepicker').datepicker();
        });
    </script>
</head>
<body>

<p>Date: <input type='text' id='datepicker'></p>

</body>
</html>
Try The Code Datepicker Widgets API Doc

jQuery UI & Datepicker: Show the week of the year

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

jQuery UI Datepicker – Show week of the year

The datepicker can show the week of the year.  There are 52 weeks to a year.  

The default calculation follows the ISO 8601 definition: the week starts on Monday, the first week of the year contains the first Thursday of the year.

This means that some days from one year may be placed into weeks ‘belonging’ to another year.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Show week of the year</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='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#datepicker').datepicker({
                showWeek: true,
                firstDay: 1
            });
        });
    </script>
</head>
<body>

<p>Date: <input type='text' id='datepicker'></p>

</body>
</html>
Try The Code Datepicker Widgets API Doc

jQuery UI & Datepicker: Datepicker with animations

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

jQuery UI Datepicker – Animations

Use different animations when opening or closing the datepicker.

Choose an animation from the dropdown, then click on the input to see its effect.

You can use one of the three standard animations or any of the UI Effects.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Animations</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='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#datepicker').datepicker();
            $('#anim').change(function () {
                $('#datepicker').datepicker('option', 'showAnim', $(this).val());
            });
        });
    </script>
</head>
<body>

<p>Date: <input type='text' id='datepicker' size='30'></p>

<p>Animations:<br>
    <select id='anim'>
        <option value='show'>Show (default)</option>
        <option value='slideDown'>Slide down</option>
        <option value='fadeIn'>Fade in</option>
        <option value='blind'>Blind (UI Effect)</option>
        <option value='bounce'>Bounce (UI Effect)</option>
        <option value='clip'>Clip (UI Effect)</option>
        <option value='drop'>Drop (UI Effect)</option>
        <option value='fold'>Fold (UI Effect)</option>
        <option value='slide'>Slide (UI Effect)</option>
        <option value=''>None</option>
    </select>
</p>

</body>
</html>
Try The Code Datepicker Widgets API Doc

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='https://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

jQuery UI & Datepicker: Dates in other months

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

jQuery UI Datepicker – Dates in other months

The datepicker can show dates that come from other than the main month being displayed. These other dates can also be made selectable.

<!doctype html>
<html lang='en'>
<head>
    <meta charset='utf-8'>
    <title>jQuery UI Datepicker - Dates in other months</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='https://codecrawl.com/code/jqueryui/jqueryui_style.css'>
    <script>
        $(function () {
            $('#datepicker').datepicker({
                showOtherMonths: true,
                selectOtherMonths: true
            });
        });
    </script>
</head>
<body>

<p>Date: <input type='text' id='datepicker'></p>

</body>
</html>
Try The Code Datepicker Widgets API Doc