Sometimes, we want to set date in input type date with JavaScript.
In this article, we’ll look at how to set date in input type date with JavaScript.
How to set date in input type date with JavaScript?
To set date in input type date with JavaScript, we can set the valueAsDate
property of the date input.
For instance, we write
document.getElementById("datePicker").valueAsDate = new Date();
to select the date input with getElementById
.
Then we set its valueAsDate
property to a date object with the current date time to set the date input’s value.
Conclusion
To set date in input type date with JavaScript, we can set the valueAsDate
property of the date input.