I am trying to set the minimum date of an HTML5 Date input based on the value set in another HTML5 Date Input.
So if you select the 3 April 2020 in the first date field, the min value of the second date input would be 3 April 2020.
I have tried using the value of the first date input, but this doesn't work. Any suggestions would be great.
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = yyyy + '-' + mm + '-' + dd;
document.getElementById("fDate").setAttribute("min", today);
function myFunction() {
var minToDate = document.getElementById("fDate").value;
document.getElementById("fDate").setAttribute("min", minToDate);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<input type="date" id="fDate" onBlur="myFunction()">
<input type="date" id="tDate">