Prevent Users from Selecting Weekends using jQuery UI DatePicker

Not known to many, jQuery UI DatePicker has a built-in function called 'noWeekends', that prevents users from selecting weekends, by disabling them.

Here’s how to use it

<html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
title></title>
<
link rel="Stylesheet" type="text/css" href="http://ajax.googleapis.
com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
<
script type="text/javascript" src="http://ajax.microsoft.com/ajax/
jquery/jquery-1.4.2.min.js"></script>
<
script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jqueryui/1.8.2/jquery-ui.min.js"></script>


<
script type="text/javascript">
$(function() {
$("#datepic").datepicker(
{ beforeShowDay: $.datepicker.noWeekends }
);
});
</script>
</
head>
<
body>
<
input id="datepic"/>
</
body>
</
html>

OUTPUT

image

As you can observe, the weekends are disabled.

See a Live Demo

1 comment:

  1. Awesome! this is just what i needed.
    The more i know about jquery, the more i like it!

    Now i just need to find a way to make datepicker skip holidays.

    Cheers!

    ReplyDelete