In my JavaScript/jQuery code, I have a text field that I run an event when the text changes using the keyup event. However currently I only account for changes done using the keyboard.
Is there a way I can detect when a text field text changed because the user did a right click and clicked on cut or delete or paste or undo?
Note: This needs to work in IE9, and preferably Firefox and chrome, but definitely needs to work in IE9.
Thanks
In my JavaScript/jQuery code, I have a text field that I run an event when the text changes using the keyup event. However currently I only account for changes done using the keyboard.
Is there a way I can detect when a text field text changed because the user did a right click and clicked on cut or delete or paste or undo?
Note: This needs to work in IE9, and preferably Firefox and chrome, but definitely needs to work in IE9.
Thanks
Share Improve this question asked Jul 22, 2013 at 20:24 sneakysneaky 2,2119 gold badges32 silver badges38 bronze badges 6- 2 stackoverflow./q/10827256 – Robert Harvey Commented Jul 22, 2013 at 20:26
- stackoverflow./q/3079722 – Robert Harvey Commented Jul 22, 2013 at 20:27
- stackoverflow./q/2903991 – Robert Harvey Commented Jul 22, 2013 at 20:27
- These are plex and should be separate questions. +1 for Robert Harvey getting it all together. – Diodeus - James MacFarlane Commented Jul 22, 2013 at 20:28
- 1 stackoverflow./a/1601484 – Robert Harvey Commented Jul 22, 2013 at 20:28
2 Answers
Reset to default 5jsFiddle Demo
Use jquery to bind an input event to the element like this:
$('#myInput').bind('input',function(){
//use this for the input element when input is made
var inputValue = this.value;//for example
});
As a start, this is not really the correct way to do it. But if you react on the mouseout event of a input you will most likely get it to behave the way you want.
$('#input').mouseout(function(){
if($('#input').is(":focus"))
console.log("Right-click");
});
Though it is to note that this might not work as well on textareas since they tend to be larger and the mouse might not be outside of it when the contextmenu has been clicked.
Note: Other than @Travis J that react to all interaction, this will (probably) only trigger an event on rightclick (and regular mouseout).