I wrote a site for my local pub and it involved a restaurant booking section. The user could select a date and a time (plus name, phone number and number of people)

The kitchen was closed on Mondays, so I needed to stop any bookings for Mondays. I had two options I could see,

  1. Server side, using PHP to check the date and refuse the request
  2. Client side, using JavaScript to block the request

I decided client side was best for the end user, otherwise they have to go back and pick a new date, etc.

I was using jquery UI’s datepicker and its very simple to just block Mondays:

$('.datebox').datepicker({
    "dateFormat"    : "DD dd/MM/yy",
    "beforeShowDay" : function(date) {
        var day_of_week = date.getDay();
        return [(day_of_week != 1), ''];
        }
    });

The day_of_week numbers start at 0 for Sunday, to 6 for Saturday. SIMPLES

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.