Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML datetime-local change event?

Is there a way to handle "datetime-selection" event with <input type='datetime-local'> control?

onchange, onselect and oninput does not work for me.

like image 605
pharkasbence Avatar asked Aug 29 '16 15:08

pharkasbence


People also ask

How do you create a calendar control with time in HTML?

The <input type="datetime-local"> defines a date picker. The resulting value includes the year, month, day, and time.

What is the difference between datetime and datetime local?

The difference between the two is that the datetime-local input does not include the time zone. If the time zone is not important to your application, use datetime-local. Some browsers are still trying to catch up to the datetime input type.


2 Answers

(In chrome) the onchange event triggers when the field is completely filled

Also have a read of Why is HTML5 input type datetime removed from browsers already supporting it?

like image 155
mplungjan Avatar answered Sep 28 '22 15:09

mplungjan


Since onchange does not occur until after the field is fully filled in I ended up doing an onselect that sends new Date() to the onchange handler if the field does not yet have a value. This eliminates the false sense of a value being set (perhaps on a backing object) on the field before the time part of dateime-local is set.

like image 31
John Culviner Avatar answered Sep 28 '22 14:09

John Culviner