javascript - Uncaught TypeError: Cannot set property 'innerHTML' of null in Character Counting in multiple textareas -
i coding page separately count characters in multiple textareas. function works fine, having error of 'uncaught typeerror: cannot set property 'innerhtml' of null' while starting type in first textarea. 2 questioned parts in console highlighted below.
can please help? how can fixed? thank much!
<script> function textcounter(textfield, showcountfield, maxamount,id) { if (textfield.value.length <= maxamount) { showcountfield.value = maxamount - textfield.value.length; document.getelementbyid('go'+id).innerhtml = ''; } else { document.getelementbyid('go'+id).innerhtml = '<span style="color:red">over!!</span>'; textfield.value = textfield.value.substring(0,maxamount); } } </script>
<body> <form> <textarea id="q" name="w" onkeyup="textcounter(this.form.q,this.form.w,5,1);" onkeypress="textcounter(this.form.q,this.form.w,5);"></textarea><br> <input type="text" name="w" value="5"></input> <p id="go1"/> </form><br> <form> <textarea id="a" name="s" onkeyup="textcounter(this.form.a,this.form.s,8,2);" onkeypress="textcounter(this.form.a,this.form.s,8); "></textarea><br> <input type="text" name="s" value="8"></input> <p id="go2"/> </form><br> </body>
the listeners onkeypress
passing 3 arguments textcounter
function requires 4. fourth argument, id
, treated undefined , call document.getelementbyid
searching element id of goundefined
.
compare:
onkeyup="textcounter(this.form.q,this.form.w,5,1);" onkeypress="textcounter(this.form.q,this.form.w,5);"
Comments
Post a Comment