Why does this not work in IE

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

    Why does this not work in IE

    I am new to javascript and would appreciate any help that is offered.
    The following script does not work in IE (the value
    (document.quote .qty1.value)is not
    displayed in the "equiptotal " field).
    Can anyone tell where I went wrong? The script works fine in
    Mozilla/Firefox.

    //The script
    function recalc() {

    document.quote. equiptotal.valu e = document.quote. qty1.value;

    }

    // The Page

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    <html>

    <head>

    <meta http-equiv="content-type" content="text/html;charset=is o-8859-1">

    <meta name="generator " content="DreamW eaver">

    <link rel="stylesheet " type="text/css" href="/css/web-soft.css">

    <title>Quotatio n</title>

    <SCRIPT LANGUAGE="JavaS cript" src="/javascript/quote.js">

    </script>

    </head>

    <BODY><center >

    <form action="" method="post" name="quote">

    <div id="quote">

    <div id="smallbar">W EB Soft Systems Inc.</div>

    Quotation

    <table class="quote" cellspacing="2" cellpadding="2" >

    <tr>

    <th>Qty</th>

    <th>Item Num</th>

    <th>Supplier</th>

    <th>Description </th>

    <th>Cost</th>

    <th>Hrs</th>

    </tr>

    <tr>

    <td class="small">< input type="text" name="qty1" size="4"
    onChange="recal c()" maxlength="4"></td>

    <td class="medium"> <input name="itemnum1" type="text" id="itemnum1"
    size="15"></td>

    <td class="medium"> <input name="supplier1 " type="text" id="supplier1"
    size="20"></td>

    <td class="large">< input name="descripti on1" type="text" id="description 1"
    size="30"></td>

    <td class="medium"> <input type="text" name="unitcost1 " size="7"></td>

    <td class="small">< input type="text" name="labor1" size="4"
    maxlength="4"></td>

    </tr>

    </table>

    <br>

    <table class="quote" cellspacing="2" cellpadding="0" >

    <tr>

    <th>Company</th>

    <th>Site</th>

    <th>Contact</th>

    <th></th>

    </tr>

    <tr>

    <td class="medlarge ">&nbsp;</td>

    <td class="medlarge ">&nbsp;</td>

    <td class="medlarge ">&nbsp;</td>

    <td><input type="submit" name="select" value="Select"> </td>

    </tr>

    </table>

    <br>

    <table class="quote" cellspacing="2" cellpadding="0" >

    <tr>

    <td class="medium" align="right">E quip Cost</td>

    <td class="medium" align="left"><i nput type="text" name="equipcost " readonly
    size="10"></td>

    <td class="medium" align="right">E quip Total</td>

    <td class="medium" align="left"><i nput type="text" name="equiptota l"
    readonly size="10"></td>

    <td class="medium" align="right">S ub Total</td>

    <td class="medium" align="left"><i nput type="text" name="subtotal" readonly
    size="10"></td>

    <td class="small" align="left"></td>

    </tr>

    <tr>

    <td class="medium" align="right">L abour Hrs</td>

    <td class="medium" align="left"><i nput type="text" name="totallabo r"
    size="10" readonly></td>

    <td class="medium" align="right">M ark-Up</td>

    <td class="medium" align="left"><i nput type="text" name="markup"
    onChange="recal c()" size="3" maxlength="4">% </td>

    <td class="medium" align="right">P ST 8%</td>

    <td class="medium" align="left"><i nput type="text" name="pst" size="10"
    readonly></td>

    <td class="small" align="left"><i nput type="checkbox" name="check1"
    value="Value1"> </td>

    </tr>

    <tr>

    <td class="medium" align="right">L abour Rate</td>

    <td class="medium" align="left"><i nput type="text" name="laborrate "
    size="10" readonly></td>

    <td class="medium" align="right">G ross Margin</td>

    <td class="medium" align="left"><i nput type="text" name="grossmarg in"
    size="10"></td>

    <td class="medium" align="right">G ST 7%</td>

    <td class="medium" align="left"><i nput type="text" name="gst" size="10"
    readonly></td>

    <td class="small" align="left"><i nput type="checkbox" name="check2"
    value="Value2"> </td>

    </tr>

    <tr>

    <td class="medium" align="right">T otal Labour</td>

    <td class="medium" align="left"><i nput type="text" name="laborcost "
    size="10" readonly></td>

    <td class="medium" align="right">G ross Profit&nbsp;</td>

    <td class="medium" align="left"><i nput type="text" name="grossprof it"
    size="10"></td>

    <td class="medium" align="right">T otal</td>

    <td class="medium" align="left"><i nput type="text" name="total" size="10"
    maxlength="10" readonly></td>

    <td class="small" align="left"><i nput type="checkbox" name="check3"
    value="Value3"> </td>

    </tr>

    </table><br>

    </div>

    <div id="footer">Cop yright&copy;200 4 R.M. Singh</div>

    </form>

    </body>

    </center>

    </html>


  • Yann-Erwan Perio

    #2
    Re: Why does this not work in IE

    rick wrote:
    [color=blue]
    > The following script does not work in IE[/color]
    [color=blue]
    > function recalc() {[/color]

    In IE, there's already a method named "recalc", it's a member of the
    document object. Your problem has to do with the function's name
    resolution (some kind of name conflict, you could say).

    <URL:http://msdn.microsoft. com/library/default.asp?url =/workshop/author/dhtml/reference/methods/recalc.asp>

    When calling the "recalc" function from the event attribute in your form
    control, the resolution of the method name follows a specific schema[1]:
    first IE looks up on the form control object whether there is a property
    named "recalc" (there's not), then it searches on the form object
    (there's not), then it searches on the document object (there's one),
    where it finds and calls the native "recalc" function - since your
    "recalc" is defined on the window object (that is, "above" the document
    object), it is never reached.

    Hey, what about using another name for your function;-)


    ---
    [1]the resolution is UA-dependent IIRC.
    ---

    HTH
    Yep.

    Comment

    • Richard Cornford

      #3
      Re: Why does this not work in IE

      rick wrote:
      <snip>[color=blue]
      > function recalc() {
      >
      > document.quote. equiptotal.valu e = document.quote. qty1.value;
      >
      > }[/color]
      <snip>[color=blue]
      > <td class="small">< input type="text" name="qty1" size="4"
      > onChange="recal c()" maxlength="4"></td>[/color]
      <snip>

      An unfortunate choice of function names. IE (from 5.5, as I recall) has
      a - document.recalc - method, and its custom scope chain for event
      handling attribute code generated functions included the - document -
      object. So when the function built from - onChange="recal c()" - is
      executed the unqualified identifier - recalc - is resolved as -
      document.recalc -, which does not do what - window.recalc - would. You
      can either change the name of the function, or fully qualify the
      reference to it in the attribute string.

      Richard.


      Comment

      • Evertjan.

        #4
        Re: Why does this not work in IE

        rick wrote on 10 apr 2004 in comp.lang.javas cript:
        [color=blue]
        > I am new to javascript and would appreciate any help that is offered.
        > The following script does not work in IE (the value
        > (document.quote .qty1.value)is not
        > displayed in the "equiptotal " field).
        > Can anyone tell where I went wrong? The script works fine in
        > Mozilla/Firefox.
        >
        > //The script
        > function recalc() {
        >
        > document.quote. equiptotal.valu e = document.quote. qty1.value;
        >[/color]

        recalc() seems to be a reserved name.

        change it to myRecalc() and you will be all right.

        --
        Evertjan.
        The Netherlands.
        (Please change the x'es to dots in my emailaddress)

        Comment

        • rick

          #5
          Re: Why does this not work in IE

          Thanks for the help, much appreaciated:-)

          "rick" <rmsingh@rogers .com> wrote in message
          news:ApTdc.2584 3$PV5.17712@new s04.bloor.is.ne t.cable.rogers. com...[color=blue]
          > I am new to javascript and would appreciate any help that is offered.
          > The following script does not work in IE (the value
          > (document.quote .qty1.value)is not
          > displayed in the "equiptotal " field).
          > Can anyone tell where I went wrong? The script works fine in
          > Mozilla/Firefox.
          >
          > //The script
          > function recalc() {
          >
          > document.quote. equiptotal.valu e = document.quote. qty1.value;
          >
          > }
          >
          > // The Page
          >
          > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
          >
          > <html>
          >
          > <head>
          >
          > <meta http-equiv="content-type" content="text/html;charset=is o-8859-1">
          >
          > <meta name="generator " content="DreamW eaver">
          >
          > <link rel="stylesheet " type="text/css" href="/css/web-soft.css">
          >
          > <title>Quotatio n</title>
          >
          > <SCRIPT LANGUAGE="JavaS cript" src="/javascript/quote.js">
          >
          > </script>
          >
          > </head>
          >
          > <BODY><center >
          >
          > <form action="" method="post" name="quote">
          >
          > <div id="quote">
          >
          > <div id="smallbar">W EB Soft Systems Inc.</div>
          >
          > Quotation
          >
          > <table class="quote" cellspacing="2" cellpadding="2" >
          >
          > <tr>
          >
          > <th>Qty</th>
          >
          > <th>Item Num</th>
          >
          > <th>Supplier</th>
          >
          > <th>Description </th>
          >
          > <th>Cost</th>
          >
          > <th>Hrs</th>
          >
          > </tr>
          >
          > <tr>
          >
          > <td class="small">< input type="text" name="qty1" size="4"
          > onChange="recal c()" maxlength="4"></td>
          >
          > <td class="medium"> <input name="itemnum1" type="text" id="itemnum1"
          > size="15"></td>
          >
          > <td class="medium"> <input name="supplier1 " type="text" id="supplier1"
          > size="20"></td>
          >
          > <td class="large">< input name="descripti on1" type="text" id="description 1"
          > size="30"></td>
          >
          > <td class="medium"> <input type="text" name="unitcost1 " size="7"></td>
          >
          > <td class="small">< input type="text" name="labor1" size="4"
          > maxlength="4"></td>
          >
          > </tr>
          >
          > </table>
          >
          > <br>
          >
          > <table class="quote" cellspacing="2" cellpadding="0" >
          >
          > <tr>
          >
          > <th>Company</th>
          >
          > <th>Site</th>
          >
          > <th>Contact</th>
          >
          > <th></th>
          >
          > </tr>
          >
          > <tr>
          >
          > <td class="medlarge ">&nbsp;</td>
          >
          > <td class="medlarge ">&nbsp;</td>
          >
          > <td class="medlarge ">&nbsp;</td>
          >
          > <td><input type="submit" name="select" value="Select"> </td>
          >
          > </tr>
          >
          > </table>
          >
          > <br>
          >
          > <table class="quote" cellspacing="2" cellpadding="0" >
          >
          > <tr>
          >
          > <td class="medium" align="right">E quip Cost</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="equipcost "[/color]
          readonly[color=blue]
          > size="10"></td>
          >
          > <td class="medium" align="right">E quip Total</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="equiptota l"
          > readonly size="10"></td>
          >
          > <td class="medium" align="right">S ub Total</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="subtotal"[/color]
          readonly[color=blue]
          > size="10"></td>
          >
          > <td class="small" align="left"></td>
          >
          > </tr>
          >
          > <tr>
          >
          > <td class="medium" align="right">L abour Hrs</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="totallabo r"
          > size="10" readonly></td>
          >
          > <td class="medium" align="right">M ark-Up</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="markup"
          > onChange="recal c()" size="3" maxlength="4">% </td>
          >
          > <td class="medium" align="right">P ST 8%</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="pst" size="10"
          > readonly></td>
          >
          > <td class="small" align="left"><i nput type="checkbox" name="check1"
          > value="Value1"> </td>
          >
          > </tr>
          >
          > <tr>
          >
          > <td class="medium" align="right">L abour Rate</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="laborrate "
          > size="10" readonly></td>
          >
          > <td class="medium" align="right">G ross Margin</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="grossmarg in"
          > size="10"></td>
          >
          > <td class="medium" align="right">G ST 7%</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="gst" size="10"
          > readonly></td>
          >
          > <td class="small" align="left"><i nput type="checkbox" name="check2"
          > value="Value2"> </td>
          >
          > </tr>
          >
          > <tr>
          >
          > <td class="medium" align="right">T otal Labour</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="laborcost "
          > size="10" readonly></td>
          >
          > <td class="medium" align="right">G ross Profit&nbsp;</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="grossprof it"
          > size="10"></td>
          >
          > <td class="medium" align="right">T otal</td>
          >
          > <td class="medium" align="left"><i nput type="text" name="total" size="10"
          > maxlength="10" readonly></td>
          >
          > <td class="small" align="left"><i nput type="checkbox" name="check3"
          > value="Value3"> </td>
          >
          > </tr>
          >
          > </table><br>
          >
          > </div>
          >
          > <div id="footer">Cop yright&copy;200 4 R.M. Singh</div>
          >
          > </form>
          >
          > </body>
          >
          > </center>
          >
          > </html>
          >
          >[/color]


          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Why does this not work in IE

            "Evertjan." <exjxw.hannivoo rt@interxnl.net > writes:
            [color=blue]
            > recalc() seems to be a reserved name.[/color]

            Not reserved, just used. In IE there is a property of that name on the
            document object. Inside an intrinsic event handler, that shadows the
            global function defined by the original poster.
            It's not that he can't call it "recalc". It's just that he can't
            refer to it as just "recalc" inside an intrinsic event handler.
            He can use "window.recalc( )" instead.
            [color=blue]
            > change it to myRecalc() and you will be all right.[/color]

            That could also work.
            /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

            • Evertjan.

              #7
              Re: Why does this not work in IE

              Lasse Reichstein Nielsen wrote on 11 apr 2004 in comp.lang.javas cript:[color=blue][color=green]
              >> change it to myRecalc() and you will be all right.[/color]
              >
              > That could also work.[/color]

              [Not specially to you. Lasse, you know this]

              My point is, that, if a function does not [seem to] get called, a
              variable does not react as it should, rename it by adding a well known
              prefix, so that you do not loose the original naming meaning.

              recalc() becomes:
              myRecalc() or:
              tempRecalc()

              An editor with a global [and case sensitive] replace will be very
              helpfull.

              =============

              btw:
              In debugging of cource, first save a copy of your work, then set
              breakpoints:

              function recalc() {
              alert("recalc function called") // BREAKPOINT
              document.quote. equiptotal.valu e = document.quote. qty1.value;
              }

              This, including the fact that no error is registered, will show you that
              the function never gets called, but NOT because of a referring mistake,
              like

              onchange="nonex istingFunction( )"

              To be even more sure, temporarily breakpoint the onchange by:

              onchange="alert ('onchange fires');recalc( );"

              --
              Evertjan.
              The Netherlands.
              (Please change the x'es to dots in my emailaddress)

              Comment

              Working...