S
S
Shimpanze2018-02-18 05:47:25
JavaScript
Shimpanze, 2018-02-18 05:47:25

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>

JS:
var content = document.getElementById('content');

// как среагировать на эту замену?
content.oninput = function() {
  alert('Значение value изменилось!');
};

Sandbox
I would be grateful for your help!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
0
0xD34F, 2018-02-18
@Shimpanze

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

O
Oleg, 2018-02-18
@politon

https://jsfiddle.net/politonius/kkj8kmk1/

S
Stalker_RED, 2018-02-18
@Stalker_RED

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 question

Ask a Question

731 491 924 answers to any question