Revision: 72789
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at December 26, 2017 15:42 by techval
Initial Code
function WordCount() { var wordsallowed = 300; var inp = document.getElementById('txtabstract').value; var regex = /\s+/gi; var wordcount = jQuery.trim(inp).replace(regex, ' ').split(' ').length; if (wordcount <= wordsallowed) { chars = inp.length; } else { var text = inp.val(); var new_text = text.substr(0, chars); document.getElementById('txtabstract').value=new_text; wordcount--; } $("#labelcount").html(wordcount); }
Initial URL
http://www.classgist.com
Initial Description
Javascript code for counting the number of words in a sentence. It can be used to allow only a certain number of words.
Initial Title
JavaScript Word Count
Initial Tags
Initial Language
JavaScript