I have the following code:
PHP
<input style="color:red;font-size:12pt;font-style:italic;"
readonly="" type="text" name="q22length" size="3" maxlength="3" value="50"/>
<textarea
onkeydown="textCounter(document.frmSurvey.q22,document.frmSurvey.q22length,50);mand();"
onkeyup="textCounter(document.frmSurvey.q22,document.frmSurvey.q22length,50)"
class="scanwid" name="q22" id="q22" rows="5" cols="">
</textarea>
Jscript
function textCounter(field,cntfield,maxlimit) {
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;
}
JsFiddle: http://jsfiddle.net/Lh2UU/
The code should count the number down in the Input tab and then stop the user from adding further characters beyond the limit set. However, it's not working and I can't see why - any suggestions?