Bizarre JS bug involving brackets (IE6/SP2)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al Reynolds

    Bizarre JS bug involving brackets (IE6/SP2)

    Afternoon,

    I have just finished fixing one of my scripts after it started
    generating odd errors on IE6 on WinXP Service Pack 2.

    For info, the IE Version is:
    6.0.2900.2180.x psp_sp2_rtm.040 803-2158
    I have done all the Windows critical updates. I haven't
    managed to replicate the behaviour in any other browser.
    I have tested the faulty version in Netscape 4.7x, IE 5
    and Opera 7 and it works fine in all three.

    The two files are here:
    http://www.exeter.ac.uk/cimt/mepres/...i1/bk8_1i2.htm (works)

    (faulty)

    There is only *one* difference between the two files in line 29.

    To make it work, I had to change:
    inputbox.value = numq+ag-cw-cc;
    to:
    inputbox.value = numq+(ag)-(cw)-(cc);

    In the faulty version, the page generates two errors while
    downloading:
    (i) Line 33 Char 16 Expected ')'
    (ii) Line 1076 Char 19 Expected ';'

    Line 33 is "pc = ((cc*100)+extra )/numq;"
    Line 1076 is "tands = 'Y8 Unit '+unit+' Section '+section;"

    In these lines, chars 16 and 19 are both "+" signs.

    Now I cannot work out for the life of me what the problem is!
    Anyone have any ideas?

    Al






  • Martin Honnen

    #2
    Re: Bizarre JS bug involving brackets (IE6/SP2)



    Al Reynolds wrote:

    [color=blue]
    > I have just finished fixing one of my scripts after it started
    > generating odd errors on IE6 on WinXP Service Pack 2.
    >
    > For info, the IE Version is:
    > 6.0.2900.2180.x psp_sp2_rtm.040 803-2158[/color]
    [color=blue]
    > http://www.exeter.ac.uk/cimt/mepres/...1i2_faulty.htm
    > (faulty)[/color]

    One thing is for sure, JavaScript comments are not done with
    <!-- comment -->
    as you seem to think and make use of in the script section on that page
    but rather need to be written as
    // comment
    for a one line comment or as
    /* comment
    comment
    */
    if you need several lines.
    Try taking those
    <!-- comment -->
    lines out and you are improving your chances that browsers do not report
    syntax errors.

    --

    Martin Honnen

    Comment

    • Al Reynolds

      #3
      Re: Bizarre JS bug involving brackets (IE6/SP2)


      "Martin Honnen" <mahotrash@yaho o.de> wrote in message
      news:415b0119$0 $8103$9b4e6d93@ newsread4.arcor-online.net...[color=blue]
      >
      > One thing is for sure, JavaScript comments are not done with
      > <!-- comment -->
      > as you seem to think and make use of in the script section on that page
      > but rather need to be written as
      > // comment
      > for a one line comment or as
      > /* comment
      > comment
      > */
      > if you need several lines.
      > Try taking those
      > <!-- comment -->
      > lines out and you are improving your chances that browsers do not report
      > syntax errors.[/color]

      So you don't know the answer to the question then? I've already
      solved the problem - the details were in my original post - so the
      format I used for my comments wasn't part of the problem. I'll
      be sure to use the correct commenting technique in the future.

      Al


      Comment

      • Michael Winter

        #4
        Re: Bizarre JS bug involving brackets (IE6/SP2)

        On Wed, 29 Sep 2004 16:23:09 +0100, Al Reynolds <ajr-news@bat400.com >
        wrote:

        [snip]
        [color=blue]
        > Now I cannot work out for the life of me what the problem is!
        > Anyone have any ideas?[/color]

        It would be nice to know how to replicate the problem. Using the system
        correctly doesn't produce errors, and it's too late for me to experiment,
        so what does?

        A couple of quick comments:

        1) Validate your pages.
        2) Why are all but one of your variables global? That's asking for trouble.
        3) Mind explaining the purpose of those eval calls in the Calculate
        function?

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Michael Winter

          #5
          Re: Bizarre JS bug involving brackets (IE6/SP2)

          On Wed, 29 Sep 2004 23:04:19 GMT, Michael Winter
          <M.Winter@bluey onder.co.invali d> wrote:

          [snip]
          [color=blue]
          > A couple of quick comments:[/color]

          Forgot an important one: making a feedback form dependent upon Javascript
          is a *very* bad idea. Using a pop-up is even worse. Contact forms
          shouldn't require anything from the user agent other than the ability to
          parse HTML. They can use more, by all means, but they shouldn't require
          more.

          [snip]

          Mike

          --
          Michael Winter
          Replace ".invalid" with ".uk" to reply by e-mail.

          Comment

          • Robert

            #6
            Re: Bizarre JS bug involving brackets (IE6/SP2)

            "Al Reynolds" <ajr-news@bat400.com > wrote in message news:<cjf35b$ds 3$1@south.jnrs. ja.net>...
            [color=blue]
            > I've already
            > solved the problem - the details were in my original post - so the
            > format I used for my comments wasn't part of the problem.[/color]


            The last lines of the original post read in my newsreader:


            "Now I cannot work out for the life of me what the problem is!
            Anyone have any ideas?"


            Seems like you were looking for any reason the script might be in
            error and it doesn't read like all the problems were solve at the
            time.


            Hard to believe there is a difference in these lines:

            To make it work, I had to change:
            inputbox.value = numq+ag-cw-cc;
            to:
            inputbox.value = numq+(ag)-(cw)-(cc);


            I'd assume the real problem code was somewhere else and this change
            just happened to avoid the problem.

            Robert

            Comment

            • Al Reynolds

              #7
              Re: Bizarre JS bug involving brackets (IE6/SP2)

              "Robert" <rccharles@my-deja.com> wrote in message
              news:c6bb75ff.0 409292029.6e8d9 265@posting.goo gle.com...[color=blue]
              > Hard to believe there is a difference in these lines:
              >
              > To make it work, I had to change:
              > inputbox.value = numq+ag-cw-cc;
              > to:
              > inputbox.value = numq+(ag)-(cw)-(cc);
              >
              >
              > I'd assume the real problem code was somewhere else and this change
              > just happened to avoid the problem.[/color]

              The two files are *identical* apart from this line.

              Al


              Comment

              • Al Reynolds

                #8
                Re: Bizarre JS bug involving brackets (IE6/SP2)


                "Al Reynolds" <ajr-news@bat400.com > wrote in message
                news:cjgij6$ogv $1@south.jnrs.j a.net...[color=blue]
                > "Robert" <rccharles@my-deja.com> wrote in message
                > news:c6bb75ff.0 409292029.6e8d9 265@posting.goo gle.com...[color=green]
                >> Hard to believe there is a difference in these lines:
                >>
                >> To make it work, I had to change:
                >> inputbox.value = numq+ag-cw-cc;
                >> to:
                >> inputbox.value = numq+(ag)-(cw)-(cc);
                >>
                >>
                >> I'd assume the real problem code was somewhere else and this change
                >> just happened to avoid the problem.[/color]
                >
                > The two files are *identical* apart from this line.
                >
                > Al[/color]

                I should have added: so you're probably right. But I can't
                work out why. There are no references to any of these
                variables anywhere else other than where they should be.

                Al[color=blue]
                >
                >[/color]


                Comment

                • Al Reynolds

                  #9
                  Re: Bizarre JS bug involving brackets (IE6/SP2)

                  "Michael Winter" <M.Winter@bluey onder.co.invali d> wrote:[color=blue]
                  > It would be nice to know how to replicate the problem.[/color]

                  If I get time, I will take out other code until the error ceases
                  appearing. I'll let you know what I find.
                  [color=blue]
                  > A couple of quick comments:
                  > 1) Validate your pages.[/color]

                  One of the problems with writing code that will work in NS4.7x
                  without excessive use of multiple code for different browsers is
                  that it doesn't do well on most validation tests. But it's a fair point.
                  [color=blue]
                  > 2) Why are all but one of your variables global? That's asking for
                  > trouble.[/color]

                  Indeed. As someone who learnt to program in the strongly-typed
                  structured environment demanded by Modula-2, almost everything
                  involved in Javascript seems like "asking for trouble" to me. As a
                  result I use naming conventions to try and avoid side-effects.
                  [color=blue]
                  > 3) Mind explaining the purpose of those eval calls in the Calculate
                  > function?[/color]

                  Probably a remnant of some NS4.7x compatible code that didn't
                  have a constant inside the brackets. These things happen when code
                  is developed in an "organic" way.
                  [color=blue]
                  > Forgot an important one: making a feedback form dependent upon Javascript
                  > is a *very* bad idea. Using a pop-up is even worse. Contact forms
                  > shouldn't require anything from the user agent other than the ability to
                  > parse HTML. They can use more, by all means, but they shouldn't require
                  > more.[/color]

                  Another fair point. Since the entire page requires javascript to
                  operate, I have used it for the feedback mechanism. The few
                  people who can't use the page because of not having Javascript
                  turned on (but can't work out why) could use the email link to
                  request some assistance.

                  Please don't ask me why I'm writing code that still work in NS4.7x.

                  Al


                  Comment

                  Working...