10

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

onchange, onselect and oninput does not work for me.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
pharkasbence
  • 957
  • 3
  • 9
  • 25
  • Welcome to SO. Please visit the [help] to see what and how to ask. HINT: Post code and effort. What does "does not work for me" mean exactly? – mplungjan Aug 29 '16 at 15:04
  • onchange triggers when the field is completely filled – mplungjan Aug 29 '16 at 15:09
  • What browser are you using? It looks like a bug in the browser, because `onchange` and `onselect` are global for all HTML elements according to the specification here: [https://www.w3.org/TR/html-markup/global-attributes.html](https://www.w3.org/TR/html-markup/global-attributes.html) – Martin Staufcik Aug 29 '16 at 15:11
  • Wow. Thanks!!! It works (onchange triggers when the field is completely filled). – pharkasbence Aug 29 '16 at 15:12

2 Answers2

3

(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?

Community
  • 1
  • 1
mplungjan
  • 169,008
  • 28
  • 173
  • 236
3

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.

John Culviner
  • 22,235
  • 6
  • 55
  • 51