Question

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

Was it helpful?

Solution

jsFiddle 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
 });

OTHER TIPS

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top