Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:49:57+00:00 2026-05-17T22:49:57+00:00

I’m trying to get my datepicker (jQuery UI Datepicker), which has one field for

  • 0

I’m trying to get my datepicker (jQuery UI Datepicker), which has one field for “check-in” and another for “check-out” to update the check-out date based on the minimum period (in seconds) pulled in via ajax when the user chooses a check-in date, but to also allow choices to be changed.

For example I want to check-in on January 1, so the check-out field updates to January 31 based on the minimum 2592000 seconds (30 days) pulled in via ajax. But then I change my mind and decide to check-in on December 31 instead, so it should let me change the check-in date to an earlier one, and update the check-out to January 30 automatically.

Below is my code with the commented out bit that almost achieves what I want except it doesn’t allow changes to earlier dates, and I’m not sure how to restrict the check-out date to the minimum period from check-in. The data pulled in via ajax also has the periods of availability so the calendar shows available days as selectable, and already booked days as not selectable. This part works fine. Any suggestions for the part that doesn’t?

$.ajax({
        url: "/ping/availability.php",
        data: "pid="+$('#pid').text(),
        dataType: "json",
        success: function(calendarEvents){
            var dates = $("#checkin, #checkout").datepicker({
                changeMonth: true,
                numberOfMonths: 1,
                /*onSelect: function(selectedDate) {
                    var option = this.id == "checkin" ? "minDate" : "maxDate";
                    var instance = $(this).data("datepicker");
                    var date = $.datepicker.parseDate(instance.settings.dateFormat || $.datepicker._defaults.dateFormat, selectedDate, instance.settings);
                    dates.not(this).datepicker("option", option, date);
                },*/
                dateFormat: 'M d, yy',
                beforeShowDay: function (date){
                    for (i = 0; i < calendarEvents.length; i++) {
                        var b,e,c;
                        b = Date.parse(calendarEvents[i]['from']);
                        e = Date.parse(calendarEvents[i]['to']);
                        c = Date.parse(date);
                        if((c <= e && c >= b)) {
                            return [true,"ui-state-notbooked"];
                        }
                    }
                    return [false, "ui-state-booked"];//disable all other days
                }
            });
        }
    });

Example ajax data showing available period and min booking length in seconds:

[{"from":"Tue, 01 Feb 2011 00:00:00 -0800","to":"Fri, 30 Sep 2011 00:00:00 -0700","min":7776000}]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:49:57+00:00Added an answer on May 17, 2026 at 10:49 pm

    http://jsfiddle.net/generalhenry/LerRw/2/

    I think I have it working

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I'm making a simple page using Google Maps API 3. My first. One marker
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.