javascript - Detect date selection on an HTML5 calendar element, but not manually entered date -


i need able run javascript function when user clicks on date in html5 calendar element. tried using onchange, fires when user types in date:

<input type="date" onchange="alert('fired');"/> 

it seems event doesn't fire until type in "complete" date, neat, doesn't meet needs.

is there way fire when date clicked on in calendar? or maybe fire in both scenarios detect type of action was?

i gather want disable keyboard input user can select valid dates mouse.

you want detect clicks inside calendar.

for have updated demo of answer:

note how click handler have empty string value clicks on invalid dates.

inputdatepreventkeyboard

please note writing event handlers in html attributes not recommended.

see https://developer.mozilla.org/en-us/docs/javascript/reference/global_objects/eval#use_functions_instead_of_evaluating_snippets_of_code

here updated code of demo:

<input type="date"     onchange="alert(window.event.type+' event handler '+this.type+' noticed  \''+this.value+'\'');"     onclick="alert(window.event.type+ ' event handler '+this.type+ ' noticed  \''+this.value+'\'');"     onkeydown="window.event.preventdefault(); alert(window.event.type+' event handler '+this.type+' prevents keyboard input value \''+this.value+'\'');"     onkeypress="window.event.preventdefault(); alert(window.event.type+' event handler '+this.type+' prevents keyboard input value \''+this.value+'\'');"     oninput="alert(window.event.type+' event handler '+this.type+' noticed \''+this.value+'\'');" /> 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -