divs, innerHTML and unknown runtime errors

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

    divs, innerHTML and unknown runtime errors

    Getting an "unknown runtime error code 0" in IE6 on the last two lines
    of the function below. Works fine in Firefox 1.5, I can't figure out
    what IE is complaining about. Both "subtotal" and "totaldiv" are divs
    with the respective ids, both contain only "$0" initially.

    function updateprice(pac kageName) {
    document.orderF orm.Subpackage. value = packageName;
    var tempsub =
    getSelectedRadi oValue(document .orderForm.subs cription);
    var sub1 = tempsub.split(" :");
    var suba = sub1[0];
    var subb = sub1[1];
    totalprice = document.orderF orm.seats.value * suba;
    shippingprice = document.orderF orm.shipping.va lue
    document.getEle mentById("total ").value = (parseInt(total price) +
    parseInt(shippi ngprice));
    document.orderF orm.subtotal.va lue = totalprice;
    document.getEle mentById('subto tal').innerHTML = '$' + totalprice;
    document.getEle mentById("total div").innerHTM L = "$" +
    (parseInt(total price) + parseInt(shippi ngprice))
    }

    The named "subtotal" child of orderForm is getting set correctly, so
    it's something about setting the innerHTML in the divs. Looked through
    the groups/googled, most of what I found referenced altering table
    structure, which I'm not doing.

    Any thoughts?

  • UnaCoder

    #2
    Re: divs, innerHTML and unknown runtime errors

    Switch to double quotes on referencing subtotal and the string, see if
    that helps

    Comment

    • marss

      #3
      Re: divs, innerHTML and unknown runtime errors


      rwalrus wrote:[color=blue]
      > var subb = sub1[1];
      > totalprice = document.orderF orm.seats.value * suba;[/color]

      You multiply two string values. Convert them to integers or floats
      before multiplication.
      (parseInt, parseFloat)

      totalprice = parseInt(docume nt.orderForm.se ats.value) * parseInt(suba);

      Comment

      • marss

        #4
        Re: divs, innerHTML and unknown runtime errors


        rwalrus wrote:[color=blue]
        > totalprice = document.orderF orm.seats.value * suba;[/color]

        You multiply two string values. You should convert it to desired type
        with "parseInt" or "parseFloat " functions.
        Eg.:
        totalprice = parseInt(docume nt.orderForm.se ats.value) * parseInt(suba);

        Maybe you problem is here.

        Comment

        • RobG

          #5
          Re: divs, innerHTML and unknown runtime errors

          marss wrote:[color=blue]
          > rwalrus wrote:
          >[color=green]
          >> var subb = sub1[1];
          >> totalprice = document.orderF orm.seats.value * suba;[/color]
          >
          >
          > You multiply two string values. Convert them to integers or floats
          > before multiplication.
          > (parseInt, parseFloat)[/color]

          That is unnecessary, strings are converted to numbers (if they can be)
          as a part of the multiplication process. If they can't, the result is
          NaN, which is not the error that the OP reported.

          [color=blue]
          > totalprice = parseInt(docume nt.orderForm.se ats.value) * parseInt(suba);[/color]

          parseInt should never be used without a radix, particularly when
          processing string input that may contain leading zeros.


          --
          Rob

          Comment

          • RobG

            #6
            Re: divs, innerHTML and unknown runtime errors

            UnaCoder wrote:[color=blue]
            > Switch to double quotes on referencing subtotal and the string, see if
            > that helps[/color]

            It shouldn't. Double and single quotes are interchangeable , provided
            they are nested correctly. There is no thing in the posted code to
            indicate that they aren't (nested correctly).




            --
            Rob

            Comment

            • RobG

              #7
              Re: divs, innerHTML and unknown runtime errors

              rwalrus wrote:[color=blue]
              > Getting an "unknown runtime error code 0" in IE6 on the last two lines
              > of the function below. Works fine in Firefox 1.5, I can't figure out
              > what IE is complaining about. Both "subtotal" and "totaldiv" are divs
              > with the respective ids, both contain only "$0" initially.[/color]

              You have a form element named 'subtotal' and a div with the same ID. IE
              doesn't like that, change one of them.

              [...]

              --
              Rob

              Comment

              • VK

                #8
                Re: divs, innerHTML and unknown runtime errors


                rwalrus wrote:[color=blue]
                > document.orderF orm.subtotal.va lue = totalprice;
                > document.getEle mentById('subto tal').innerHTML = '$' + totalprice;[/color]

                .... which suggests that you have a form element and a DIV named
                "subtotal" (I guess the same with "total"). You cannot do that in IE,
                because it implements a broken namespace schema.

                Go through you page (and any others if needed) and make sure that *no
                one* ID on the page repeats an ID *or* NAME of a form element. So say
                if you have:
                <input type="text" name="subtotal" id="subtotalID" >
                you cannot use neither "subtotal" nor "subtotalID " anywhere else: nor
                for div's, nor for iframe's, nor for nothing.

                Correct this and it will work (unless of course you have other errors
                in your script :-)

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: divs, innerHTML and unknown runtime errors

                  marss wrote:
                  [color=blue]
                  > rwalrus wrote:[color=green]
                  >> var subb = sub1[1];
                  >> totalprice = document.orderF orm.seats.value * suba;[/color]
                  >
                  > You multiply two string values. Convert them to integers or floats
                  > before multiplication.
                  > (parseInt, parseFloat)[/color]

                  As Rob said.

                  Furthermore, there is only one external numerical type in the corresponding
                  ECMAScript implementations as yet: `number', an IEEE-754 double-precision
                  floating-point number value, no matter its string representation (such as
                  with window.alert()) . In those implementations , unsigned 32-bit Integers
                  are used internally only. parseInt() and parseFloat() do not convert a
                  string value to an integer value or a float value, respectively. Both
                  merely parse a string in a certain way and return the corresponding
                  `number' value.


                  PointedEars

                  Comment

                  • rwalrus

                    #10
                    Re: divs, innerHTML and unknown runtime errors [solved]

                    VK wrote:[color=blue]
                    > rwalrus wrote:[color=green]
                    > > document.orderF orm.subtotal.va lue = totalprice;
                    > > document.getEle mentById('subto tal').innerHTML = '$' + totalprice;[/color]
                    >
                    > ... which suggests that you have a form element and a DIV named
                    > "subtotal" (I guess the same with "total"). You cannot do that in IE,
                    > because it implements a broken namespace schema.
                    >
                    > Go through you page (and any others if needed) and make sure that *no
                    > one* ID on the page repeats an ID *or* NAME of a form element. So say
                    > if you have:
                    > <input type="text" name="subtotal" id="subtotalID" >
                    > you cannot use neither "subtotal" nor "subtotalID " anywhere else: nor
                    > for div's, nor for iframe's, nor for nothing.
                    >
                    > Correct this and it will work (unless of course you have other errors
                    > in your script :-)[/color]

                    That fixed it. Thanks for the help. Most of the underlying code and
                    markup I'm trying to maintain is not mine, and pretty hackwork, so a
                    lot of these bizzare errors keep cropping up. I appreciate the help.

                    --
                    Ryan W

                    Comment

                    • VK

                      #11
                      Re: divs, innerHTML and unknown runtime errors [solved]


                      rwalrus wrote:[color=blue]
                      > That fixed it. Thanks for the help. Most of the underlying code and
                      > markup I'm trying to maintain is not mine, and pretty hackwork, so a
                      > lot of these bizzare errors keep cropping up. I appreciate the help.[/color]

                      You are welcome. I'd just like to point out that the original code did
                      not contain any documented execution-prohibitive mistakes.

                      OK, I don't like "lazy syntacs" for forms
                      (document.order Form.subtotal.v alue instead of
                      document.forms['orderForm'].elements['subtotal'].value). But this may
                      lead to a real mistake only in some particular circumstances - with
                      some "strange" form and elements names - and it was not a case here.

                      The real reason was in the brocken IE's namespace which is by design
                      and you are not responsible for. First of all, all HTML elements in IE
                      with ID's are being added to a special undocumented namespace between
                      global vars and Host Object. Secondly NAME's and ID's are being treated
                      equally and equally added to this space. Together it produces a real
                      mess. There is absolutely no reason for <input name="subtotal" > to have
                      any conflicts with <div id="subtotal"> . And it doesn't anywhere: except
                      IE.

                      Comment

                      Working...