javascript - Displaying Sum Of Characters and Sum Of Words -
this script counts characters , words 3 separate textarea inputs , echo's out sum. variable sum of characters (chars_all) working, variable sum of words (words_all) returning same number.
if return single words variable (words1, words2, words3), works intended. issue seems in getting final sum.
here's relevant piece of code
setinterval(function(){ var chars1 = $('#content_ifr').contents().find('body').text(); var words1 = chars1.split(" "); var chars2 = $('#contentsection2_ifr').contents().find('body').text(); var words2 = chars2.split(" "); var chars3 = $('#contentsection3_ifr').contents().find('body').text(); var words3 = chars3.split(" "); var chars_all = chars1+chars2+chars3; var words_all = words1+words2+words3; $(".textarea_chars_all").text(chars_all.length); $(".textarea_words_all").text(words_all.length); }, 2000)
just clarify, code return correct number
$(".textarea_words_all").text(words1.length);
while code not
$(".textarea_words_all").text(words_all.length);
you should use var words_all = words1.concat(words2, words3);
because words1, words2 , words3 arrays.
Comments
Post a Comment