Click here to Skip to main content
11,649,476 members (76,894 online)
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 >

can anyone point on a problem here guys ?? (i know the code block is cut in the middle, ok)
noam
Posted 28-Mar-12 17: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 F-ES Sitecore 354
1 OriginalGriff 324
2 Kornfeld Eliyahu Peter 309
3 CPallini 295
4 Sergey Alexandrovich Kryukov 254
0 OriginalGriff 1,577
1 Sergey Alexandrovich Kryukov 1,087
2 CPallini 1,015
3 DamithSL 996
4 jyo.net 994


Advertise | Privacy | Mobile
Web04 | 2.8.150804.4 | 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