Hi,
I have a number of textareas which I've called 1S, 1I, 2S, 2I etc. and I am trying to prevent a user from entering more than 125 characters.
I found a great function
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>
to be used with:
<textarea name="1S" cols="50" rows="8" style="font-family:verdana;font-size:10px;" onKeyDown="textCounter(this.form.1S,this.form.remLen,125);" onKeyUp="textCounter(this.form.1S,this.form.remLen,125);"></textarea>
The problem is it doesn't seem to like the form field beginning with a number. Is there a way round this that doesn't involve renaming all of my fields?
Thanks very much
Ed
I have a number of textareas which I've called 1S, 1I, 2S, 2I etc. and I am trying to prevent a user from entering more than 125 characters.
I found a great function
<SCRIPT LANGUAGE="JavaScript">
<!-- Original: Ronnie T. Moore -->
<!-- Web Site: The JavaScript Source -->
<!-- Dynamic 'fix' by: Nannette Thacker -->
<!-- Web Site: -->
<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! -->
<!-- Begin
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}
// End -->
</script>
to be used with:
<textarea name="1S" cols="50" rows="8" style="font-family:verdana;font-size:10px;" onKeyDown="textCounter(this.form.1S,this.form.remLen,125);" onKeyUp="textCounter(this.form.1S,this.form.remLen,125);"></textarea>
The problem is it doesn't seem to like the form field beginning with a number. Is there a way round this that doesn't involve renaming all of my fields?
Thanks very much
Ed