Categories
JavaScript Answers

How to set date in input type date with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *