Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 :

XML
<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

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
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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 30-Mar-12 4:53am    
5!
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:
JavaScript
myElement = document.smsform.txt2;
str = myElement.textContent || myElement.innerText;


—SA
 
Share this answer
 
v2
Comments
Peter_in_2780 29-Mar-12 0:16am    
Missed that one (probably misread it as InnerHTML). Looks like OP is using a VERY old book. ;) Have 5.
Sergey Alexandrovich Kryukov 29-Mar-12 0:18am    
Yeee... Thank you, Peter.
--SA
ProEnggSoft 29-Mar-12 1:29am    
+5
Sergey Alexandrovich Kryukov 29-Mar-12 10:51am    
Thank you.
--SA
Monjurul Habib 30-Mar-12 4:53am    
5!

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900