Ad

Jquery Not Triggering Change When Textbox Changes Occurs From Copy-paste With Mouseclick

- 1 answer

I'm listening to changes in a textbox using keyup and change as the events. This works when you type with the keyboard or do a copy paste also with the keyboard (Ctrl-V).

The problem is that when a user right-clicks on the textbox and pastes text, the change is not detected until the user clicks somewhere else on the page, and so things look broken. Here's the jsFiddle and here's the code:

function Start() {

    $('#test').on({
    change: OutputTxt,
    keyup: OutputTxt
  })
}

function OutputTxt() {
    $('#output').text($('#test').val());
}

$(Start);

How do I change this so that a change that occurs with copy-paste is detected as soon as the pasting is done. Note: I tried adding a click event but it doesn't help.

Ad

Answer

Try on input:

    $('#test').on({
        input: OutputTxt,
      })
Ad
source: stackoverflow.com
Ad