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.
please note writing event handlers in html attributes not recommended.
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
Post a Comment