G
Garry Jones
I have been using this code for sometime. I can use it to show the user how
many remaining characters are reamaining in a text area. Now I need to
develop the code and dont know where to start.
These are the three parts of the working code
1) Javascript
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1)
taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
2) Live output to user
You have max 255 chars. You have <span id=myCounter>255</span> remaining
chars
3) Textarea code
<textarea cols=40 rows=7 wrap=virtual onkeypress="return taLimit()"
onkeyup="return taCount(myCounter)" maxLength="255"></textarea>
The problem is that now I need to show the user some existing text
(contained in a variable) in the textarea which he/she can edit or add to.
The initial number is the number of remaining characters shown by my code is
a static 255. If 120 characters are left and one is added it changes from
255 remaining to 119. (119 is correct).
When the textarea is initially displays I would like it to subtract the
number of characters contained in the variable from "maxlength" and display
the true ammount of remaining characters.
Can anyone point me in the right direction?
Garry Jones
Sweden
many remaining characters are reamaining in a text area. Now I need to
develop the code and dont know where to start.
These are the three parts of the working code
1) Javascript
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj.maxLength*1) return false;
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.maxLength*1)
taObj.value=taObj.value.substring(0,taObj.maxLength*1);
if (visCnt) visCnt.innerText=taObj.maxLength-taObj.value.length;
}
2) Live output to user
You have max 255 chars. You have <span id=myCounter>255</span> remaining
chars
3) Textarea code
<textarea cols=40 rows=7 wrap=virtual onkeypress="return taLimit()"
onkeyup="return taCount(myCounter)" maxLength="255"></textarea>
The problem is that now I need to show the user some existing text
(contained in a variable) in the textarea which he/she can edit or add to.
The initial number is the number of remaining characters shown by my code is
a static 255. If 120 characters are left and one is added it changes from
255 remaining to 119. (119 is correct).
When the textarea is initially displays I would like it to subtract the
number of characters contained in the variable from "maxlength" and display
the true ammount of remaining characters.
Can anyone point me in the right direction?
Garry Jones
Sweden