nonphoto nonphoto - 7 months ago 20
Javascript Question

Prevent input event from firing when changing textarea programmatically

I have a

textarea
that can be edited by the user. I occasionally update the text programmatically by changing the element's
value
property. I need an event that triggers when the user changes the text, but not when the program changes it. Is this possible?

Answer

use keyup as the event trigger which will allow the user activity to trigger the function but not if you do it programmatically

addEvent(document.getElementById('textArea_id'), 'keyup', function(event) {
//function goes here
});