MSIE incompatibility

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

    #1

    MSIE incompatibility

    Anyone have any idea why the following would work on Netscape 7.x but not
    MSIE ? Thanks, Ike

    <input type=button onClick="recalc ()" value="Recalc Form">
    ..
    ..
    ..

    <SCRIPT LANGUAGE="JavaS cript">
    <!--
    function recalc() {
    alert("ok");
    var x = document.seller sestnetproceeds .saleprice.valu e;
    document.seller sestnetproceeds .statetransfert ax.value = x/1000*4;
    var tits= x/1000;
    var mn = 175;
    alert(tits);
    if(tits<=10000 && tits>500)
    document.seller sestnetproceeds .titleinsurance .value = 150 * 5.75 + 100 * 4.5
    + 250 * 3.5 +(tits-500) * 2.75 ;
    else if(tits<=500 && tits>250)
    document.seller sestnetproceeds .titleinsurance .value = 150 * 5.75 + 100 * 4.5
    +(tits-250) * 3.5 ;
    else if(tits<=250 && tits>150)
    document.seller sestnetproceeds .titleinsurance .value = 150 * 5.75+(tits-150)
    * 4.5 ;
    else if(tits<=150){
    if( tits * 5.75>mn)
    document.seller sestnetproceeds .titleinsurance .value = tits * 5.75 ;
    else
    document.seller sestnetproceeds .titleinsurance .value = mn;
    }
    var
    totalcosts=Math .abs(document.s ellersestnetpro ceeds.titleexam .value)+Math.ab s
    (document.selle rsestnetproceed s.escrowfee.val ue)+Math.abs(do cument.sellerse s
    tnetproceeds.mi scfees.value)+M ath.abs(documen t.sellersestnet proceeds.deed.v a
    lue)+Math.abs(d ocument.sellers estnetproceeds. watersewerdepos it.value)+Math. a
    bs(document.sel lersestnetproce eds.homewarrant y.value)+Math.a bs(document.sel l
    ersestnetprocee ds.fhavacosts.v alue)+Math.abs( document.seller sestnetproceeds .
    buyerscredits.v alue)+Math.abs( document.seller sestnetproceeds .propertytaxes. v
    alue)+Math.abs( document.seller sestnetproceeds .statetransfert ax.value)+Math. a
    bs(document.sel lersestnetproce eds.titleinsura nce.value)+Math .abs(document.s e
    llersestnetproc eeds.realestate commissions.val ue);
    document.seller sestnetproceeds .netproceeds.va lue = Math.abs(x) - totalcosts;
    }
    //-->
    </SCRIPT>


  • Lasse Reichstein Nielsen

    #2
    Re: MSIE incompatibility

    "Ike" <rxv@hotmail.co m> writes:
    [color=blue]
    > Anyone have any idea why the following would work on Netscape 7.x but not
    > MSIE ?[/color]

    Not really. It's also impossible to test without the HTML page that
    it manipulates, and unguessable when you don't say what the error is.

    I can offer some suggestions for making it easier to read, and therefore
    debug:
    [color=blue]
    > <SCRIPT LANGUAGE="JavaS cript">[/color]

    The type attribute is required in HTML 4, and is always sufficient. Use:
    <script type="text/javascript">
    [color=blue]
    > <!--[/color]

    That HTML comment isn't necessary.
    [color=blue]
    > function recalc() {
    > alert("ok");
    > var x = document.seller sestnetproceeds .saleprice.valu e;[/color]

    You are writing this *a lot*. Try making a local variable. I recommend:

    var form = document.forms['sellersestnetp roceeds'].elements;
    var x = form.saleprice. value;
    [color=blue]
    > document.seller sestnetproceeds .statetransfert ax.value = x/1000*4;[/color]

    form.stattrafer tax.value = x/1000*4;
    [color=blue]
    > if(tits<=10000 && tits>500)
    > document.seller sestnetproceeds .titleinsurance .value = 150 * 5.75 + 100 * 4.5
    > + 250 * 3.5 +(tits-500) * 2.75 ;[/color]

    Don't post lines longer than ~72 characters. Your news client has broken
    the line, which introduces errors in your script that anyone trying to help
    you must fix before trying the code.

    I recommend using { and } around the branches of an if, even if it is
    only one line. It saves bugs in the long run, and I even think it makes
    the code easier to read.

    (We fixed a bug today at work that turned out to be a two line else
    branch without surrounding { and } ... i.e., the second line was
    executed always!)
    [color=blue]
    > var
    > totalcosts=Math .abs(document.s ellersestnetpro ceeds.titleexam .value)+Math.ab s
    > (document.selle rsestnetproceed s.escrowfee.val ue)+Math.abs(do cument.sellerse s
    > tnetproceeds.mi scfees.value)+M ath.abs(documen t.sellersestnet proceeds.deed.v a
    > lue)+Math.abs(d ocument.sellers estnetproceeds. watersewerdepos it.value)+Math. a
    > bs(document.sel lersestnetproce eds.homewarrant y.value)+Math.a bs(document.sel l
    > ersestnetprocee ds.fhavacosts.v alue)+Math.abs( document.seller sestnetproceeds .
    > buyerscredits.v alue)+Math.abs( document.seller sestnetproceeds .propertytaxes. v
    > alue)+Math.abs( document.seller sestnetproceeds .statetransfert ax.value)+Math. a
    > bs(document.sel lersestnetproce eds.titleinsura nce.value)+Math .abs(document.s e
    > llersestnetproc eeds.realestate commissions.val ue);[/color]

    What a whopper (and the subject of erroneous wrapping!)

    I assume Math.abs is being used to convert the argument to a
    number. There are other ways to do that. I prefer the Number function,
    but a simple prefixed "+" can do the same.


    Here is another function that does what I think you want. If it doesn't
    look right, then I am misteading your intentions:

    <script type="text/javascript">
    function recalc() {
    var form = document.forms['sellersestnetp roceeds'].elements;
    var x = form.saleprice. value;
    form.statetrans fertax.value = x / 250;
    var tits = x / 1000;
    var mn = 175;
    var ti;
    if (tits <= 150) {
    ti = Math.max(tits * 5.75, mn);
    } else if (tits <= 250) {
    ti = 862.5 + (tits - 150) * 4.5;
    } else if (tits <= 500) {
    ti = 862.5 + 450 + (tits - 250) * 3.5;
    } else { // didn't really mean <= 10000 ?
    ti = 862.5 + 450 + 875 + (tits - 500) * 2.75;
    }
    form.titleinsur ance.value = ti;
    var totalcosts = Number(form.tit leexam.value) +
    Number(form.esc rowfee.value) +
    Number(form.mis cfees.value) +
    Number(form.dee d.value) +
    Number(form.wat ersewerdeposit. value) +
    Number(form.hom ewarranty.value ) +
    Number(form.fha vacosts.value) +
    Number(form.buy erscredits.valu e) +
    Number(form.pro pertytaxes.valu e) +
    Number(form.sta tetransfertax.v alue) +
    ti +
    Number(form.rea lestatecommissi ons.value);
    form.netproceed s.value = x - totalcosts;
    }
    </script>
    ---


    Good luck
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: MSIE incompatibility

      Lasse Reichstein Nielsen wrote:[color=blue]
      > "Ike" <rxv@hotmail.co m> writes:[color=green]
      >> <!--[/color]
      >
      > That HTML comment isn't necessary.[/color]

      It is actually an SGML Markup Declaration Open (MDO) delimiter ("<!")
      followed by an SGML comment delimiter ("--"; the concatenation of both
      has been called Comment Declaration Open -- CDO). But you are right,
      this practice of "commenting out" scripts should be considered obsolete,
      despite recommended by the HTML 4.01 Specification, as only badly borken
      user agents require it (HTML 2.0 is obsolete, HTML 3.2 defines the
      "script" element) and those should not be supported any longer.
      [color=blue]
      > [...] I assume Math.abs is being used to convert the argument to a
      > number. There are other ways to do that. I prefer the Number function,
      > but a simple prefixed "+" can do the same.[/color]

      Although less efficient than Number() or the unary "+" operator,
      parseInt() and parseFloat() are recommended in most cases as their
      second argument provides for evaluation of the string based on a
      number base. Unless the user is explicitely told what effect
      leading zeroes (octal) and letters (hexadecimal) in input may
      have, those two methods should be preferred.

      Another advantage of the methods above the unary "+" is that they
      are supported in every implementation, while the operator is not
      as it has been introduced in later versions of JavaScript.


      PointedEars
      --
      .... realism: HTML 4.01 Strict
      evangelism: XHTML 1.0 Strict
      madness: XHTML 1.1 as application/xhtml+xml
      -- Bjoern Hoehrmann

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: MSIE incompatibility

        Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> writes:
        [color=blue]
        > Lasse Reichstein Nielsen wrote:[/color]
        [color=blue][color=green]
        >> That HTML comment isn't necessary.[/color]
        >
        > It is actually an SGML Markup Declaration Open (MDO) delimiter ("<!")
        > followed by an SGML comment delimiter ("--"; the concatenation of both
        > has been called Comment Declaration Open -- CDO).[/color]

        I'm using "HTML comment" in the sense of:
        <URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4>
        [color=blue]
        > Although less efficient than Number() or the unary "+" operator,
        > parseInt() and parseFloat() are recommended in most cases as their
        > second argument provides for evaluation of the string based on a
        > number base.[/color]

        parseFloat doesn't have a second argument. For that alone, I would
        prefer it to parseInt, since the second argument is usually forgotten.

        However, the reason I don't use or recommend these functions is that
        they accept arbitrary garbage at the end of the string. That canmask
        a typo more easily than a leading zeros or x's. E.g., the string
        12,222.12 (US notation of 12222 + 12/100 with a thousands separator)
        would be accepted by parseFloat with the result 12, whereas Number
        would give NaN.
        [color=blue]
        > Unless the user is explicitely told what effect leading zeroes
        > (octal) and letters (hexadecimal) in input may have,[/color]

        The Number function trigger octal interpretation for leading zeros (as
        parseInt does in some non-ECMA-compliant implementations ). It does accept
        "0x" as marking hexadecimal.

        If input format should be restricted, it is necessary to check the
        format before converting independently of whether one uses Number or
        parseFloat. After that, I recommend Number for its combination of
        efficiency and readability.
        [color=blue]
        > those two methods should be preferred.[/color]

        I disagree.
        [color=blue]
        > Another advantage of the methods above the unary "+" is that they
        > are supported in every implementation, while the operator is not
        > as it has been introduced in later versions of JavaScript.[/color]

        The Number function has "only" been with us since Netscape 3, whereas
        parseFloat was included in Netscape 2. If a browser using Netscape's
        Javascript 1.0 is being used today, no doubt string to number
        conversion will be the least of ones worries.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: MSIE incompatibility

          Lasse Reichstein Nielsen wrote:[color=blue]
          > Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> writes:[color=green]
          >> Lasse Reichstein Nielsen wrote:[color=darkred]
          >>> That HTML comment isn't necessary.[/color]
          >>
          >> It is actually an SGML Markup Declaration Open (MDO) delimiter ("<!")
          >> followed by an SGML comment delimiter ("--"; the concatenation of both
          >> has been called Comment Declaration Open -- CDO).[/color]
          >
          > I'm using "HTML comment" in the sense of:
          > <URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4>[/color]

          Not the only place where inexact information can be found in W3C
          Recommendations . And exactly this place has lead to the common
          misconception that comments in HTML begin with "<!--" and end
          with "-->", rather than begin with "--" and end with "--" but
          only in SGML context. This has resulted in invalid comments in
          HTML documents like

          <!--------------------- heading --------------------->

          where the number of "-" is not a factor of 4 as required in that
          context. User agents that display standards compliant behavior
          in this regard, like Mozilla/5.0 in Standards Compliance Mode,
          will not render the markup following this "comment" while borken
          user agents, like IE, will.
          [color=blue][color=green]
          >> Although less efficient than Number() or the unary "+" operator,
          >> parseInt() and parseFloat() are recommended in most cases as their
          >> second argument provides for evaluation of the string based on a
          >> number base.[/color]
          >
          > parseFloat doesn't have a second argument.[/color]

          True, my bad. Yet it should have one.
          [color=blue]
          > For that alone, I would prefer it to parseInt, since the second
          > argument is usually forgotten.[/color]

          I would not, not generally. It depends on the application.
          [color=blue]
          > However, the reason I don't use or recommend these functions is that
          > they accept arbitrary garbage at the end of the string. That canmask
          > a typo more easily than a leading zeros or x's. E.g., the string
          > 12,222.12 (US notation of 12222 + 12/100 with a thousands separator)
          > would be accepted by parseFloat with the result 12, whereas Number
          > would give NaN.
          >
          >[color=green]
          >>Unless the user is explicitely told what effect leading zeroes
          >>(octal) and letters (hexadecimal) in input may have,[/color]
          >
          > The Number function trigger octal interpretation for leading zeros (as
          > parseInt does in some non-ECMA-compliant implementations ). It does accept
          > "0x" as marking hexadecimal.[/color]

          Which is a problem, do you not see?
          [color=blue]
          > If input format should be restricted, it is necessary to check the
          > format before converting independently of whether one uses Number or
          > parseFloat. After that, I recommend Number for its combination of
          > efficiency and readability.[/color]

          That is shortsighted reasoning. A user will be disallowed to type
          leading zeroes or you are forced to string them prior because they
          represent octals, although it is a deprecated feature. With parseInt()
          and 10 as second argument or parseFloat(), that would not happen.
          Instead, if there is garbage input that can be parsed, it can be
          checked for it converting the result to string and compare with
          the original value. Or if there is garbage input that cannot be
          parsed, the parse...() methods return NaN as well.
          [color=blue][color=green]
          >> those two methods should be preferred.[/color]
          >
          > I disagree.[/color]

          That's your opinion. But if your main argument is a typo, consider all
          the typos that are possible in an input. Technics cannot solve social
          problems.
          [color=blue][color=green]
          >> Another advantage of the methods above the unary "+" is that they
          >> are supported in every implementation, while the operator is not
          >> as it has been introduced in later versions of JavaScript.[/color]
          >
          > The Number function has "only" been with us since Netscape 3, whereas
          > parseFloat was included in Netscape 2. If a browser using Netscape's
          > Javascript 1.0 is being used today, no doubt string to number
          > conversion will be the least of ones worries.[/color]

          I was not arguing against the Number() function here, but against the
          unary "+". Arguing with the age of Netscape versions is not very sound
          when it comes to JavaScript implementations .


          PointedEars

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: MSIE incompatibility

            Thomas 'PointedEars' Lahn <PointedEars@nu rfuerspam.de> writes:
            [color=blue]
            > Lasse Reichstein Nielsen wrote:[color=green]
            >> I'm using "HTML comment" in the sense of:
            >> <URL:http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4>[/color]
            >
            > Not the only place where inexact information can be found in W3C
            > Recommendations .[/color]

            The ISO HTML standard is more precise, and requires exactly one
            comment in each comment declaration.
            [color=blue][color=green]
            >> parseFloat doesn't have a second argument.[/color]
            >
            > True, my bad. Yet it should have one.[/color]

            I guess it was omitted because most people have a hard time thinking
            in decimals in other bases. Since parseFloat also accepts scientific
            notation (e.g., 2.3E4 == 23000), it is hard to generalize to
            hexadecimal, where "e" is a digit (in hexadecimal, 2.3E4 is (decimal)
            2.2431640625).

            In practice, I have yet to see a problem where the solution was
            made easier by using non-10 based fractional numbers.
            [color=blue][color=green]
            >> For that alone, I would prefer it to parseInt, since the second
            >> argument is usually forgotten.[/color]
            >
            > I would not, not generally. It depends on the application.[/color]

            If the argument is an integer, the two functions should agree on the
            result. If not, I don't necessarily want my conversion function to do
            the rounding. If parseInt had defaultet to base 10 when no second
            argument was present, I wouldn't have a problem with it, but as it is,
            I don't want to recommend it to people. It is too fragile.
            [color=blue][color=green]
            >> The Number function trigger octal interpretation for leading zeros (as
            >> parseInt does in some non-ECMA-compliant implementations ).[/color][/color]

            I meant to say that it *doesn't* trigger octal mode.
            Number("00012") == 12
            [color=blue][color=green]
            >> It does accept "0x" as marking hexadecimal.[/color]
            >
            > Which is a problem, do you not see?[/color]

            I see there is a problem with triggering octal interpretation for
            prefixed zeros. The parseInt function does that in some
            implementations (it shouldn't according to ECMA 262). The Number function
            doesn't.

            The problem with a prefixed "0x" is less likely to happen
            accidentally, and all string->number conversion functions recognizes
            it, except parseInt *with* a second argument.

            ....[color=blue]
            > That's your opinion. But if your main argument is a typo, consider all
            > the typos that are possible in an input. Technics cannot solve social
            > problems.[/color]

            The only difference between parseInt, parseFloat and Number is how they
            treat input that is not a pure non-zero-prefixed integer.

            s parseInt(s) parseInt(s,10) parseFloat(s) Number(s)
            -------------------------------------------------------------
            12 12 12 12 12
            012 12/10 12 12 12
            0x12 18 0 18/0 18
            12.2 12 12 12.2 12.2
            12E4 12 12 120000 120000
            12cm 12 12 12 NaN

            (values separated by slashes is found using Opera 7 and IE 6
            respectively)

            Which behavior is preferred obviously depends on the problem at hand.
            I prefer Number to parseInt/Float because it doesn't silently accept
            garbage at the end of the string. It is a problem that parseInt/
            parseFloat behaves differently in Opera (and othe erstandards
            complaint browsers) and in IE. And I don't like the second argument
            of parseInt being necessary, because I know it will be forgotten
            too often.

            Your weighing of the different behaviors might differ, and I doubt
            there is a single obvious "best" method to use.

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: MSIE incompatibility

              Lasse Reichstein Nielsen <lrn@hotpop.com > writes:
              [color=blue]
              > I see there is a problem with triggering octal interpretation for
              > prefixed zeros. The parseInt function does that in some
              > implementations (it shouldn't according to ECMA 262).[/color]

              I take that back. Both behaviors are allowed by ECMA 262v3 (section
              15.1.2.2, algorithm step 12).

              As for parseFloat, it should parse the longest possible prefix of its
              input as a StrDecimalLiter al. It seems it is Opera that fails this,
              since it parses "0x12" as 18, not 0. I'll report it.

              /L
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • Dr John Stockton

                #8
                Re: MSIE incompatibility

                JRS: In article <40EAF9CE.20703 03@PointedEars. de>, seen in
                news:comp.lang. javascript, Thomas 'PointedEars' Lahn
                <PointedEars@nu rfuerspam.de> posted at Tue, 6 Jul 2004 21:13:18 :
                [color=blue]
                > But you are right,
                >this practice of "commenting out" scripts should be considered obsolete,
                >despite recommended by the HTML 4.01 Specification, as only badly borken
                >user agents require it (HTML 2.0 is obsolete, HTML 3.2 defines the
                >"script" element) and those should not be supported any longer.[/color]

                It is naive to assume that a file which will be processed by user agents
                is a file which will be processed only by user agents.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
                <URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang. javascript
                <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
                <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

                Comment

                Working...