Reputation: 665
I am using listeners to detect when a user finishes with textbox; when the text is value is changed, I am pasting their text on to the page using innerHTML.
document.getElementById("dateinput").addEventListener("change", function() {
myDate(document.getElementById("dateinput").value);
}, false);
Is there a way to listen for each key press to immediately paste the .value character by character as they type? I only want to do this while the textbox has focus.
Thanks.
Upvotes: 3
Views: 10994
Reputation: 253416
Yes, the events are keyup
, keydown
, keypress
or, in contemporary browsers, input
(which covers any user-initiated, non-programmatic, event in the relevant <input>
element).
References:
Upvotes: 9
Reputation: 23208
you can use an of keyup/keydown/keypress
document.getElementById("dateinput").addEventListener("keyup", function() {
myDate(document.getElementById("dateinput").value);
}, false);
you can use onpaste
document.getElementById("dateinput").addEventListener("paste", function() {
myDate(document.getElementById("dateinput").value);
}, false);
Upvotes: 5