When entering a first date in form field with ID dateInput
and running the function showEndDate
the inputDate + 21 days
is outputted to the console successfully but no maximum is being set on form field with ID end_date
.
What is incorrect with my use of setAttribute("max", inputDate)
. ?
I have tested entering a fixed value such as setAttribute("max", '2021-10-31')
and this works 31st Oct does get set correctly as the upper max value in the date field ! :( :S
// Declare values for use in functions
let dateInput = document.getElementById("dateInput");
var endDateInput = document.getElementById("end_date");
// Shows the end date field
function showEndDate() {
var inputValue = dateInput.value;
var inputDate = new Date(inputValue);
if(inputValue != "") {
document.getElementById("panel").style.display = "block";
} else {
alert("Date cannot be blank");
}
inputDate.setDate(inputDate.getDate() + 21);
console.log(inputDate);
endDateInput.setAttribute("max", inputDate);
}
<input id="dateInput" type="date" name="manufacture_one" required ></div>
also end date:
<input id="end_date" type="date" name="holiday_end_date" >