Click here to Skip to main content
12,951,619 members (55,473 online)
Rate this:
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
    function counter(method,cnt)    //accepts lang method and calc num of msgs
            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

can anyone point on a problem here guys ?? (i know the code block is cut in the middle, ok)
Posted 28-Mar-12 17:48pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

See[^] (and many others) for why you shouldn't use document.all Use document.getElementByID instead.
document.all is an obsolete IE4 monstrosity.

SAKryukov 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.
Monjurul Habib 30-Mar-12 4:53am
Rate this: bad
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:[^].

One cross-browser compatibility trick is using both in the following way:
myElement = document.smsform.txt2;
str = myElement.textContent || myElement.innerText;

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.
SAKryukov 29-Mar-12 0:18am
Yeee... Thank you, Peter.
ProEnggSoft 29-Mar-12 1:29am
SAKryukov 29-Mar-12 10:51am
Thank you.
Monjurul Habib 30-Mar-12 4:53am
SAKryukov 30-Mar-12 11:17am
Thank you, Monjurul.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,084
CHill60 3,480
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,830

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 29 Mar 2012
Copyright © CodeProject, 1999-2017
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