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 sets valueAsDate property to a date object.

For instance, we write

document.getElementById("datePicker").valueAsDate = new Date();

to select theg date input with getElementById.

Then we set its valueAsDate property to a date object.

Conclusion

To set date in input type date with JavaScript, we sets valueAsDate property to a date object.

Leave a Reply

Your email address will not be published.