Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
JavaScript datepicker for reservation system

Im working on a website similar to a hotel reservation system. Users are allowed to book a room using the website.

These are the unavailable dates:

['2021-11-17', '2021-11-18', '2021-11-19', '2021-11-20', '2021-11-27', '2021-11-28']

In my datepicker, I wish to do these:

  1. Only future dates, and check-out date shouldn't be earlier than check-in date
  2. To grey out the unavailable dates so that users cant choose them
  3. If the user choose to check-in on 2021-11-11, the check-out option range until 2021-11-16

My current JS:

const dateCheck = ['2021-11-17', '2021-11-18', '2021-11-19', '2021-11-20', '2021-11-27', '2021-11-28']

function disableDates(date) {
  var string = jQuery.datepicker.formatDate("yy-mm-dd", date);
  return [dateCheck.indexOf(string) == -1]
}


$("#listingCheckIn").datepicker({
  beforeShowDay: disableDates,
  minDate: 0,
  dateFormat: "yy-mm-dd",
  showOn: "both",
  //upon selection     
  onSelect: function(dateText, inst) {
    $("#listingCheckOut").datepicker("option", "minDate",
      $("#listingCheckIn").datepicker("getDate")); //2nd datepicker to set min value for 1st datepicker
  }
});

$("#listingCheckOut").datepicker({
  beforeShowDay: disableDates,
  minDate: 0,
  dateFormat: "yy-mm-dd",
  onSelect: function(dateText, inst) {
    $("#listingCheckOut").datepicker("option", "minDate",
      $("#listingCheckIn").datepicker("getDate")); //2nd datepicker to set min value for 1st datepicker
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>

<form action="booking.php" id="bookingForm" method="post">
  <div id="C_rightColumn">
    <div class="C_rcTopBox flex-c-c">
      Rates
    </div>

    <div class="C_rcTopBox flex-c-c">
      <label>Check-In Date</label>
      <input type="text" id="listingCheckIn" name="checkin" class="date">
    </div>

    <div class="C_rcTopBox flex-c-c">
      <label>Check-Out Date</label>
      <input type="text" id="listingCheckOut" name="checkout" class="date">
    </div>

    <div class="C_rcBtmBox">
      <button type="submit" class="btn" name="bookProperty">Book Now!</button>
    </div>
  </div>
</form>

Basically, 1 and 2 is a go, but how do I achieve 3 so that a user must check out before the check-in of other bookings? Thanks in advance.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda