Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hello im trying to count chars ans words and determine if its heb or eng in a regular textarea control, usig javascript, but none of this works in firefox, can someone please help me?
 
my code :
 
<script type="text/javascript">
 
    function langChk()
    {
        var str = new String(document.smsform.txt2.innerText.toString());
        var i = 0;
        var cnt = str.length;
        if(cnt == 0)
        {
            document.all('msgCounter').innerHTML = "0"
            document.all('chrCounter').innerHTML = "0"
        }
 
        for(i=0 ; i < cnt ; i++) // will not start unless cnt > 0
        {
            var ch = parseInt(str.charCodeAt(i));
 
            if(ch >= 1488 && ch <=1514) //chk 4 heb
            {
                counter(1,cnt);
                break;
            }
            else
                counter(2,cnt);
        }
    }
 
    function counter(method,cnt)    //accepts lang method and calc num of msgs
    {
 
        switch(method)
        {
            case 1 :
                if(cnt > 0 && cnt <= 70)
                    document.all('msgCounter').innerHTML = "1";
                if(cnt > 70 && cnt <= 134)
                    document.all('msgCounter').innerHTML = "2";
                if(cnt > 134 && cnt <= 201
 
</script>
 
can anyone point on a problem here guys ?? (i know the code block is cut in the middle, ok)
noam
Posted 28-Mar-12 18:48pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

See http://simonwillison.net/2003/Aug/11/documentAll/[^] (and many others) for why you shouldn't use document.all Use document.getElementByID instead.
document.all is an obsolete IE4 monstrosity.
 
Cheers,
Peter
  Permalink  
Comments
SAKryukov at 29-Mar-12 0:09am
   
I think you are right (my 5), but I found another incompatibility in the very beginning of the code, "innerText", please see my answer.
--SA
Monjurul Habib at 30-Mar-12 4:53am
   
5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

First problem which caught my eyes was using the property innerText. The official W3C property is textContent; and Mozilla tends to support the standards, unlike IE. Please see:
https://developer.mozilla.org/En/DOM/Node.textContent[^].
 
One cross-browser compatibility trick is using both in the following way:
myElement = document.smsform.txt2;
str = myElement.textContent || myElement.innerText;
 
—SA
  Permalink  
v2
Comments
Peter_in_2780 at 29-Mar-12 0:16am
   
Missed that one (probably misread it as InnerHTML). Looks like OP is using a VERY old book. ;) Have 5.
SAKryukov at 29-Mar-12 0:18am
   
Yeee... Thank you, Peter.
--SA
ProEnggSoft at 29-Mar-12 1:29am
   
+5
SAKryukov at 29-Mar-12 10:51am
   
Thank you.
--SA
Monjurul Habib at 30-Mar-12 4:53am
   
5!
SAKryukov at 30-Mar-12 11:17am
   
Thank you, Monjurul.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 275
1 OriginalGriff 230
2 BillWoodruff 173
3 CPallini 155
4 Kamal Rocks 144
0 OriginalGriff 5,655
1 DamithSL 4,506
2 Maciej Los 3,997
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 29 Mar 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100