Jump to content

Date Picker to check availability


brad_langdon

Recommended Posts

Can anyone tell me how to use a jquery date picker in a way that it checks whether or not the selected date is available?

 

So basically if a date is not available it would gray out the unavailable dates or something similar. I want to use it for a booking system but I am not sure how to do this part. I guess it would have to fetch the info from a database or could it all be done somehow in the javascript file?

 

Thanks  ;)

Link to comment
Share on other sites

Typically a date picker does not have the functionality you want, it will simply allow you to choose a date from a calendar and then submit that to be checked on the server side. You could I'm sure add the functionality of disabling dates but you would have to tie that into an ajax call and it could get complex.  Is it not easier to just them first select the date and then submit it for a check?  Doing that is rather simple because the datepicker is simply going to give your text in date format that you can easily check with php and then give the user feedback.  Or you can have a reponse area and do an ajax call that says if that date is available or not.  This way you still get an immediate response but don't have to edit the calendar code.

Link to comment
Share on other sites

Here is how i did it in the past.  The disableDays function you see being called basically looks at the current date to see if its available.

 

The reportForm2.html is backend script that returns a JSON object of all available days.

 

$.getJSON("reportForm2.html", {id: itemId}, function(data, textStatus) {
global = data; 
  $('#fromDate, #toDate').datepicker({ 
    dateFormat: 'mm/dd/yy', 
    showOn: "button",  
    buttonImage: "images/icons/calendar.png", 
    buttonImageOnly: true,
    changeYear: true,
    changeMonth: true,
    duration:0,
    showButtonPanel: true  ,
    beforeShowDay: disableDays
  });
});

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.