I'm learning JS and I'm making form where user sets date, and I want to limit it to todays date. I'm using JS for this, but it doesn't work despite the fact that it works for others.
Here is my HTML:
<div class="form">
<form>
Jméno<br>
<input type="text" placeholder="Jméno"><br>
Datum vyhození<br>
<input type="date" id="datum" max="2018-7-1">
<input type="submit" value="odeslat">
<input type="reset" value="Začít znovu">
</form>
</div>
Here is my JS:
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1;
var yyyy = today.getFullYear();
if(dd<10){
dd='0'+dd
}
if(mm<10){
mm='0'+mm
}
today = yyyy+'-'+mm+'-'+dd;
var datum = document.getElementById("datum");
datum.setAttribute("min", today);
Error message in Chrome is:
Uncaught TypeError: Cannot set property 'min' of null
at today.js:14
Can you tell me where is the mistake? Thank you.