Last Updated: February 25, 2016
·
969
· iantearle

Setting input[type=date] with Javascript

To save a lot of head scratching, if you need to programatically set a date input with Javascript you will need to pass the string as toISOString() and remove additional characters from the end using substring().

You may run into timezone issues, setting the Date.UTC object does the trick.

new Date(Date.UTC(this.currentYearView, this.currentMonthView, e.target.innerHTML)).toISOString().substring(0, 10);