1

I need to execute some code every time the user writes in a textarea. Currently, I am listening for a keyup-event, but the latest years predictive keyboards has become normal on mobile devices. This does not trigger my event handler. It also does not get triggered when the user uses right click to paste text into the textarea.

Is there any event that let's me execute code also when the user changes the content of the textarea without pressing keys?

tjespe
  • 704
  • 7
  • 17
  • 2
    Have you tried the onchange event? – Michiel Jan 16 '17 at 17:13
  • 1
    Possible duplicate of [Textarea onchange detection](http://stackoverflow.com/questions/2823733/textarea-onchange-detection) – Michiel Jan 16 '17 at 17:14
  • @Michiel That doesn't fire on every change, usually only when the element loses focus – James Thorpe Jan 16 '17 at 17:15
  • That is absolutely true. For a full answer, you should check the duplicate link above. It suggest using a combination of keyup and change events, with links to code samples. – Michiel Jan 16 '17 at 17:17
  • Maybe you could try using the `oninput` event, as per this other question: http://stackoverflow.com/a/33646354/679240 – Haroldo_OK Jan 16 '17 at 17:17
  • @Michiel I agree with the dupe - but the [not-accepted answer](http://stackoverflow.com/a/14029861/791010) on that question is the one to go for. Removed my answer here in deference. – James Thorpe Jan 16 '17 at 17:20

1 Answers1

0

The solution for me, since I was using AngularJS for this project, was using $scope.$watch. This allows a function to be triggered every time a variable in the scope changes, and will trigger also when the user is using a predictive keyboard.

tjespe
  • 704
  • 7
  • 17