I am creating a web page for translating texts piece-by-piece. The user is supposed to fill many textareas and press the "save" button when done. The save button is inactive by default, and becomes active on keypress, keyup, and keydown. This, however, doesn't cover the case when text is pasted using a mouse, by right-clicking and pressing "Paste" or by middle-clicking (middle-click pasting is common in X Windows). This pasting scenario is relatively common on the web page that I am creating.
The "change" event would work, but it's only fired after the textarea loses focus. Is there a way to get that mouse pasting event to be triggered immediately when the text changes?
Thank you!
The onchange JavaScript event is triggered when an element is changed and then loses focus. In the context of a textarea , this happens when the content of the textarea is modified and then the textarea loses focus because the user clicks away or presses the tab key.
$('#textareaID'). on('input change keyup', function () { if (this. value. length) { // textarea has content } else { // textarea is empty } });
$("textarea").on("change keyup keydown paste cut copy", function(e) {
// do something
});
You can attach any event, you want to. Cut, Copy and Paste. I added all of them!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With