JSFiddle - React, Tailwind, and code Playground
by mustafa yılmaz
HTML
<input id="a" type="text" /><br/>
<input id="b" type="text" /><br/>
<input id="c" type="text" /><br/>
<input id="finalcount" value="0" disabled />
JavaScript
$(function() {
var wordCounts = {};
$("input[type='text']:not(:disabled)").each(function() {
var input = '#' + this.id;
word_count(input);
$(this).keyup(function() {
word_count(input);
})
});
function word_count(field) {
var number = 0;
var matches = $(field).val().match(/\b/g);
if (matches) {
number = matches.length / 2;
}
wordCounts[field] = number;
var finalCount = 0;
$.each(wordCounts, function(k, v) {
finalCount += v;
});
$('#finalcount').val(finalCount)
}
});