This article will help you create your own javascript/jQuery word count function. The code below can be used to limit the number of words in a text box(e.g Abstract guideline tool) using the simple javascript with a little bit mix of jQuery.
function WordCount() {
var inp = document.getElementById('txtabstract').value;
var regex = /\s+/gi;
var wordcount = jQuery.trim(inp).replace(regex, ' ').split(' ').length;
$("#labelcount").html(wordcount);
}
Here is the working example which can help you count the number of words in a textbox using the code below
Text here : <input type="text" id="txtabstract" value="Testing Word Count" />
Count : <label id="labelcount"></label>
jQuery
function WordCount() {
//Get Text data
var inp = document.getElementById('txtabstract').value;
var regex = /\s+/gi;
var wordcount = jQuery.trim(inp).replace(regex, ' ').split(' ').length;
$("#labelcount").html(wordcount);
}
$(document).ready(function(){
//count word on page load
WordCount();
//count word on entering text in TextBox
$("#txtabstract").on('input',function(){
WordCount();
})
})
https://jsfiddle.net/Lrhbv6zv/
Similar code is used to check the total number of words when a user is submitting a project material at Classgist