I made a simple words counter to count the number of words in an HTML text box. It takes the data from the inputText field in the html doc, and counts how many actual words are in it. I can not get it to display the word count in the box. What am I doing wrong?
function count_words(evt) {
var input = document.getElementById('inputText').value;
var words = 0;
input = count_words().replace(/(< ([^>]+)<)/g, '').replace(/\s+/g, ' ');
input = input.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
words = input.split(' ').length;
words = document.getElementById('numberOfWords').innerHTML;
}
window.onload = function (evt) {
if (document && document.getElementById) {
document.getElementById('btnConvert').onclick = count_words;
}
}
<textarea id="inputText" cols="30" rows="6">The quick brown fox jumps over the lazy dog.</textarea>
<br>
<input type="button" id="btnConvert" value="Word Count">
<input id="numberOfWords" type="text" value="" size="6">