Skip to content
Advertisement

set the input type = date min from another input type = date

Hi i’m a rookie in html and been struggling in this inputs,

<label>Check-In Date :  </label>
<input id ="date1" type="date" name="from" min=<?php echo date('Y-m-d', strtotime("+3 days"));;?>>    
<label>Check-Out Date : </label>
<input id = "date2" type="date" name="to">

i just want to know how to set the second input minimum date from the first input selected value? i’ve already searched and i just can’t get the right answer…

Advertisement

Answer

PHP is server-side script that only runs on the server (not on the client). For a more detailed explanation of client-side vs server-side scripting please view this


To accomplish what you want, you would use client-side script like JavaScript you can easily achieve this.

Below is jQuery that will update the second field whenever the first field is changed.

jQuery

$("input[name='from']").change(function() {
  $("input[name='to']").val($(this).val());
})

Make sure to include jQuery so that the above loads: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement