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