I am trying to assign a well formatted string variable (yyyy-mm-dd) representing a date, to the value of an <input type="date" />
. When the value is a string literal, it works, however when it is coming from a variable or a constant, it doesn't work. You may check the following html code and the rendered html page.
<form>
<p>Litteral Assignement: <input name="literalDate" type="date" /></p>
<p>Variable Assignement: <input name="variableDate" type="date" /></p>
</form>
<script>
var literalDateControl = document.querySelector('input[name="literalDate"]');
literalDateControl.value = "2019-07-24";
var today = new Date();
const todayValue = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
var variableDateControl = document.querySelector('input[name="variableDate"]');
variableDateControl.value = todayValue;
</script>
Any idea or suggestions on how to address that?