Click here to Skip to main content
11,803,861 members (76,333 online)
Rate this: bad
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 >

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 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.
Monjurul Habib at 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 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.
ProEnggSoft at 29-Mar-12 1:29am
SAKryukov at 29-Mar-12 10:51am
Thank you.
Monjurul Habib at 30-Mar-12 4:53am
SAKryukov at 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
0 OriginalGriff 450
1 CPallini 320
2 F-ES Sitecore 240
3 Sergey Alexandrovich Kryukov 234
4 CHill60 220
0 OriginalGriff 3,000
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,755
4 Richard MacCutchan 1,187

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