Hi
I have several textarea in the same page. I would like to count the
words in each textarea without any interaction with each other. Here's
the code I used for the count :
<script type="text/javascript">
/*Téléchargé sur Easy-Script.com (http://www.easy-script.com)
Trouvé sur: www.portugal-tchat.com */
var ns6=document.ge tElementById&&! document.all
function restrictinput(m axlength,e,plac eholder){
if (window.event&& event.srcElemen t.value.length> =maxlength)
return false
else if
(e.target&&e.ta rget==eval(plac eholder)&&e.tar get.value.lengt h>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/
if (pressedkey.tes t(String.fromCh arCode(e.which) ))
e.stopPropagati on()
}
}
function countlimit(maxl ength,e,placeho lder){
var theform=eval(pl aceholder)
var lengthleft=maxl ength-theform.value.l ength
var placeholderobj= document.all? document.all[placeholder] :
document.getEle mentById(placeh older)
if (window.event|| e.target&&e.tar get==eval(place holder)){
if (lengthleft<0)
theform.value=t heform.value.su bstring(0,maxle ngth)
placeholderobj. innerHTML=lengt hleft
}
}
function displaylimit(th ename, theid, thelimit){
var theform=theid!= ""? document.getEle mentById(theid) : thename
var limit_text='<b> <span
id="'+theform.t oString()+'">'+ thelimit+'</span></b> caractères
maximum.'
if (document.all|| ns6)
document.write( limit_text)
if (document.all){
eval(theform).o nkeypress=funct ion(){ return
restrictinput(t helimit,event,t heform)}
eval(theform).o nkeyup=function (){ countlimit(thel imit,event,thef orm)}
}
else if (ns6){
document.body.a ddEventListener ('keypress', function(event) {
restrictinput(t helimit,event,t heform) }, true);
document.body.a ddEventListener ('keyup', function(event) {
countlimit(thel imit,event,thef orm) }, true);
}
}
</script>
This code works if there's only one textarea. If there's more than one,
the word count change in the first text area, not the second... How can
I fix that?
Here's a example :
<form name=form>
<textarea name="descripti on" id="esp" rows="4" cols="22"
style="border: 1px double #B8C8FE; background-color: #0069B3; color:
#FFCC00;"></textarea>
<br>
<font face="verdana" size="2"
color="#B8C8FE" ><script>displa ylimit("","esp" ,250)</script><br></font>
<textarea name="descripti on1" id="esp1" rows="4" cols="22"
style="border: 1px double #B8C8FE; background-color: #0069B3; color:
#FFCC00;"></textarea>
<br>
<font face="verdana" size="2"
color="#B8C8FE" ><script>displa ylimit("","esp1 ",250)</script><br></font>
</form>
As you can see, the id is different. But when I write words in the
second textarea, the text change in the 1st text area, not the second.
I'm completely lost because i've never learnt used Javascript... Can
anyone help plz?
Thanks