ChaCol ChaCol - 25 days ago 13
Javascript Question

How to set HTML5 Form min restriction for datepicker to "Check-In Date (user input)"

What do I need to add for the min restriction to make sure the user-input for check-out date is after the user-input for check-in date?



<form>
Enter Check-In Date:<br>
<input type="date" name="checkin"><br>

Enter Check-Out Date:<br>
<input type="date" name="checkout"><br>
</form>





Can this be done with just HTML5 or does it need to include javascript?

Answer

java script need for validation .Compare the check in date is less the check out date

function check() {
  if(document.getElementById('checkin').value < document.getElementById('checkout').value)
    { console.log('ok')}
  else{
    console.log('Not allowed')
    }
  
  }
<form>
      Enter Check-In Date:<br>
      <input type="date" id="checkin" name="checkin"><br>
      Enter Check-Out Date:<br>
      <input type="date" id="checkout" name="checkout" onchange="check()"><br>
    </form>

Comments