Answer the question
In order to leave comments, you need to log in
JavaScript: how to track changes in the value of a textarea?
Hello!
What event should be used to track the change in the value value of a textarea? Not innerHTML, but value.
I tried:
HTML:
<button onclick="content.value = content.value.replace('Lorem', 'LOREM')">Заменить</button>
<textarea name="" id="content" cols="80" rows="10">Lorem ipsum — классическая панграмма, условный, зачастую бессмысленный текст-заполнитель, вставляемый в макет страницы.</textarea>
var content = document.getElementById('content');
// как среагировать на эту замену?
content.oninput = function() {
alert('Значение value изменилось!');
};
Answer the question
In order to leave comments, you need to log in
You can define your own value property on the element you are interested in, or rewrite the HTMLTextAreaElement.prototype.value setter so that when the value is set, the event you need is generated.
https://codepen.io/anon/pen/GQywpG?editors=1010
Watch for an input or change
event
In extreme cases, you can watch for reyup/keydown
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question