function PrepareCounter() {
var ct = 1;
while(document.getElementById("id_answer"+ct)) {
document.getElementById("id_answer"+ct).setAttribute("onFocus", "countChars('textbox','char_count',140)", "onKeyDown", "countChars('textbox','char_count',140)", "onKeyUp", "countChars('textbox','char_count',140)");
ct += 1;
}
}
If i focus my element countChars is executed but if i write something it’s not.
setAttributeonly takes 2 arguments, you would have to call each of those separately.Rather than using strings, you can use real functions: