Example here: http://jsfiddle.net/67XDq/1/
I have the following HTML:
17.
-
There are two issues in the fiddle
- no form element
- script mode was onload, which means that window object didnt have
textCounter function
see updated fiddle http://jsfiddle.net/67XDq/7/, markup:
17.
Questions? Maximum of 500 characters -
characters left
and code
function textCounter(field, cnt, maxlimit) {
var cntfield = document.getElementById(cnt)
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}
- 热议问题