Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sherl0ck's avatar

Javascript input date conditional choice

this maxdate should not enter a value before the date in the previous field.

<div class="col-sm-2">
                           <div class="form-sh">
                              <input id="mindate" type="date" min="<?php echo date("Y-m-d"); ?>" name="mindate">
                           </div>
                        </div> 
						<div class="col-sm-2">
                           <div class="form-sh">
                              <input onchange="updateInput(this.value)" id="maxdate" type="date" min="<?php echo date("Y-m-d"); ?>" name="maxdate">
                           </div>
                        </div>

Javascript

$(document).ready( function() {
    $('#mindate').val(new Date().toDateInputValue());
	$('#maxdate').val(new Date().toDateInputValue());
});​

					 function updateInput(ish){
						 var mindate = document.getElementById("mindate");
					 document.getElementById("maxdate").value = mindate;
					 $('input[name="maxdate"]').val(mindate);
					}
0 likes
0 replies

Please or to participate in this conversation.