I wrote a simple script to count words while typing in form
My question is why by changing the value of the word_count field when typing;
The EventListener of word_count is not fired
document.getElementById('subject').addEventListener('change', function() {
var string = this.value
string = string.replace(/s+/g, " ");
var words = string.split(/s+/).length;
document.getElementById('word_count').value = words;
}, false);
document.getElementById('subject').addEventListener('keypress', function() {
var string = this.value
string = string.replace(/s+/g, " ");
var words = string.split(/s+/).length;
document.getElementById('word_count').value = words;
}, false);
document.getElementById('word_count').addEventListener('change', function() {
alert('change fired');
}, false);
<form>
<div> <label for="story">string:</label>
<textarea id="subject" name="subject"></textarea>
</div>
<div> <label for="story">count:</label>
<input id="word_count">
</div>
</form>