Results 1 to 6 of 6

Thread: FF1 and IE6 JavaScript parsers/readers/w-e are screwed up...

  1. #1
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default FF1 and IE6 JavaScript parsers/readers/w-e are screwed up...

    I was writing a code to calculate any three numbers with each of the four arithmetic signs (+,-,*,/) alternating positions in the two slots. A simplified version of the troublesome code is below. In both FF1 and IE6, it comes up with the number 11 for (x+x)/x and 21 for (10+5)/5, and FF1 then deletes the text. (I thought maybe it was just the IE6 parser, so I tried FF1. I'm assuming FF1 has a completely separate problem.) I find that if I feed the number directly into the JS -(5+5)/5-, it comes up with 2, the correct answer, but can't handle input variables. It's apparently calculating y/x and z/x and adding the quotients as strings, so (10+5)/5="2"+"1" and (5+5)/5="1"+"1".
    Code:
    <html>
     <head>
      <title>
       Oddness...
      </title>
      <script type="text/javascript">
       function calc(x,y,z){
        var problemChild=y+z
        var yzxaddidiv=problemChild/x
        ABC=Math.round(yzxaddidiv)
        if(yzxaddidiv!=ABC){
         yzxaddidiv="N/A"
        }
        document.getElementById("output").value=yzxaddidiv
       }
      </script>
     </head>
     <body>
      <form id="calc">
       <input type=text id="x" />
       <input type=text id="y" />
       <input type=text id="z" />
       <button onClick=calc(x.value,y.value,z.value)>Calculate</button>
      </form>
      <form id="result">
       <textarea id="output" rows="10" cols="30"></textarea>
      </form>
     </body>
    </html>
    Is this everyone's computer or just mine? Anyone know how to get around it?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not at all surprising. Use parseInt(y) to convert y to integer form.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    Thanks. I appreciate that very much. I've never needed that function before and some things I thought were legal are now illegal in JavaScript. Did Netscape do an online update of JavaScript? I know I never approved one...

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Heh, what century are you from?
    So-called "Javascript" these days is a variety of implementations of ECMA-262, and I'm afraid strings take precedence in a + operation, no matter what you prefer.

    We have things called HTML validators these days too.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jul 2006
    Posts
    497
    Thanks
    8
    Thanked 70 Times in 70 Posts

    Default

    I only recently resumed coding, after a hiatus of about a year, probably. I learned my JS, XML, HTML, [insert client-side language here] at W3Schools and high school WebMastering class, and I was told a string required quotes. And what in the world is ECMA? In answer to your question, I'm from the 20th century, lol.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    And what in the world is ECMA?
    ECMA is an international standards regulation body, much like ISO, IETF, and ANSI. This formidable beastie is ECMA-262. It's the accepted standard to which the various forms of "Javascript" (JScript, JavaScript, &c.) are meant to conform. Mike (mwinter) has explained it several times, and probably a lot better than I could, if you search.
    I was told a string required quotes.
    Only when creating a new one. Form element values, among other things, are returned as strings.

    W3Schools has obtained quite a reputation recently for "errors, omissions and deceit!" as frequently announced by the resident #javascript bot. However, I continue to link to it as reference material because the URLs are easy to remember.
    Last edited by Twey; 07-25-2006 at 10:16 PM.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •