Replace:
onkeydown="characterCounter(commentsCounter,250, this)"
onkeyup="characterCounter(commentsCounter,250, this)">
With
onkeydown="characterCounter('commentsCounter',250, this)"
onkeyup="characterCounter('commentsCounter',250, this)">
And
function characterCounter(spanId, maxLen, inputElement)
{
if (spanId)
With
function characterCounter(id, maxLen, inputElement)
{
spanId = document.getElementById(id);
if (spanId)
Your code as it stands, expects commentsCounter to be a globally accessible variable. In order to access the element with id commentsCounter, you must use document.getElementById