(function () { var div, txt; div = document.getElementById('charcount'); txt = document.getElementById('inputfield'); setInterval(function () { div.innerHTML = txt.value.length; }, 10); txt.focus(); })();