Problem...help

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

    Problem...help

    Can someone tell me where the problem here is? I can't get the "squared()"
    function to work properly...it supposed to put the squared value into the
    iframe area.

    Thanks,
    Ed

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <script type="text/javascript">
    //Square Root
    function squareroot()
    {
    x=document.root
    data=x.num.valu e
    var sqr=Math.sqrt(d ata)
    parent.sqrt.doc ument.write(sqr )
    }
    //Squared of an item
    function squared()
    {
    x=document.squa re
    data=x.num.valu e
    var sum=data*data
    parent.squaredf rame.document.w rite()
    }
    //Tanget
    function tangent()
    {
    x=document.tang ent
    data=x.num.valu e
    var tan=Math.tan(da ta)
    parent.tangentf rame.document.w rite(tan)
    }
    //Refresh Values
    function refresh()
    {
    location.reload (sqrt)
    location.reload (squaredframe)
    location.reload (tangentframe)
    }
    </script>
    </head>

    <body>
    <table width="100%" border="1">
    <tr>
    <td width="73%" height="50">
    <form name="root">
    Type in a number to compute the square root of the value.
    <input name="num2" type="text" id="num" size="10" maxlength="10">
    <input name="button" type="button" onClick="square root()"
    value="Compute" >
    </form></td>
    <td width="27%" height="50"><if rame name="sqrt" width="100%" height="50"
    frameborder="0" scrolling="no"> </iframe></td>
    </tr>
    <tr>
    <td height="50">
    <form name="square">
    Type in a number to compute the square of the value.
    <input name="num3" type="text" id="num2" size="10" maxlength="10">
    <input name="button2" type="button" onClick="square d()"
    value="Compute" >
    </form></td>
    <td><iframe name="squaredfr ame" width="100%" height="50" frameborder="0"
    scrolling="no"> </iframe></td>
    </tr>
    <tr>
    <td height="50">
    <form name="tangent">
    Type in a number to compute the tanget of the value.
    <input name="num" type="text" id="num3" size="10" maxlength="10">
    <input name="button3" type="button" onClick="tangen t()"
    value="Compute" >
    </form></td>
    <td><iframe name="tangentfr ame" width="100%" height="50" frameborder="0"
    scrolling="no"> </iframe></td>
    </tr>
    </table>
    <div align="right">
    <form name="refresh">
    Hit refresh to compute new values.
    <input type="button" onClick="refres h()" value="Refresh Values">
    </form>
    </div>
    </body>
    </html>

  • Lasse Reichstein Nielsen

    #2
    Re: Problem...help

    Ed Blinn <eblinn@sbcglob al.net> writes:
    [color=blue]
    > Can someone tell me where the problem here is? I can't get the "squared()"
    > function to work properly...it supposed to put the squared value into the
    > iframe area.[/color]

    Does the other functions work? (No, not in my browsers)
    [color=blue]
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">[/color]

    This DOCTYPE triggers quirks mode. New pages should not be made for
    quirks mode.
    [color=blue]
    > function squareroot()
    > {
    > x=document.root[/color]

    I prefer
    var x = document.forms['root'];
    [color=blue]
    > data=x.num.valu e[/color]

    and
    var data = x.elements['num'].value;

    It is much easier to read, and is guaranteed to work in all W3C DOM
    browsers too.
    [color=blue]
    > var sqr=Math.sqrt(d ata)[/color]

    Why make "sqr" a local variable, but not "x" or "data"?
    [color=blue]
    > parent.sqrt.doc ument.write(sqr )[/color]

    The sqrt frame is not a subframe of the parent document, but of this
    document (that is why the other functions didn't work for me, I tested
    them in an iframe, so "parent" isn't equal to "self").

    frames['sqrt'].document.write (sqr);
    [color=blue]
    > function squared()
    > {
    > x=document.squa re
    > data=x.num.valu e[/color]

    The form "document.f orms['square']" doesn't hae an element called
    "num". It has name="num3" and id="num2".

    ....[color=blue]
    > <form name="square">[/color]
    ....[color=blue]
    > <input name="num3" type="text" id="num2" size="10" maxlength="10">[/color]

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Dr John Stockton

      #3
      Re: Problem...help

      JRS: In article <he3dwp2m.fsf@h otpop.com>, seen in
      news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
      posted at Tue, 16 Sep 2003 02:32:17 :-[color=blue]
      >[color=green]
      >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">[/color]
      >
      >This DOCTYPE triggers quirks mode. New pages should not be made for
      >quirks mode.[/color]

      What, then, do you recommend?

      ISTM that one should choose a <!DOCTYPE ...> (or not to have one), and
      then adjust the code until it validates (which involves choosing a
      validator).

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

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: Problem...help

        Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
        [color=blue][color=green]
        > >This DOCTYPE triggers quirks mode. New pages should not be made for
        > >quirks mode.[/color]
        >
        > What, then, do you recommend?[/color]

        I recommend deciding on a verions of HTML, in this case version 4.01
        Transitional is fine, and the adding a document type declaration for
        that version that puts new browsers into standards mode.
        That would be:

        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/transitional.dt d">

        If in doubt, add the appropriate URL for the DTD, that always gives
        standards mode.

        Opera's page about it, with links to MSDN and Mozilla:
        <URL:http://www.opera.com/docs/specs/doctype/>
        [color=blue]
        > ISTM that one should choose a <!DOCTYPE ...> (or not to have one), and
        > then adjust the code until it validates (which involves choosing a
        > validator).[/color]

        If all the DOCTYPE did was define the HTML version, then you could
        probably do without it, as long as you tell the validator what HTML
        version to check against.

        Since the DOCTYPE declaration does double duty as a trigger for
        backwards (or bugwards) compatabilty with pages written directly to
        the CSS/rendering bugs of IE 4, new pages should not be written
        without a DOCTYPE or with a DOCTYPE that triggers quirks mode.

        Ofcourse, I believe in writing to the official standards. Other people
        don't care, and will gladly write pages targeted at browsers which can
        emulate IE4 (currently includes later IEs, Mozilla and Opera 7, and
        maybe others).

        These people also live in caves and eat roots (or maybe I am just
        channeling Dogbert).

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • DU

          #5
          Re: Problem...help

          Lasse Reichstein Nielsen wrote:[color=blue]
          > Dr John Stockton <spam@merlyn.de mon.co.uk> writes:
          >
          >[color=green][color=darkred]
          >>>This DOCTYPE triggers quirks mode. New pages should not be made for
          >>>quirks mode.[/color]
          >>
          >>What, then, do you recommend?[/color]
          >
          >
          > I recommend deciding on a verions of HTML, in this case version 4.01
          > Transitional is fine, and the adding a document type declaration for
          > that version that puts new browsers into standards mode.
          > That would be:
          >
          > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          > "http://www.w3.org/TR/html4/transitional.dt d">
          >
          > If in doubt, add the appropriate URL for the DTD, that always gives
          > standards mode.
          >[/color]

          This will still trigger Safari in backward compatible mode and in
          "almost" standards mode in Mozilla. Best is to always use a strict DTD
          with full url (case sensitive):

          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">

          Aalto University, Finland is a new multidisciplinary science and art community in the fields of science, business, and art and design.

          [color=blue]
          > Opera's page about it, with links to MSDN and Mozilla:
          > <URL:http://www.opera.com/docs/specs/doctype/>
          >[color=green]
          >>ISTM that one should choose a <!DOCTYPE ...> (or not to have one), and
          >>then adjust the code until it validates (which involves choosing a
          >>validator).[/color]
          >
          >
          > If all the DOCTYPE did was define the HTML version, then you could
          > probably do without it, as long as you tell the validator what HTML
          > version to check against.
          >
          > Since the DOCTYPE declaration does double duty as a trigger for
          > backwards (or bugwards) compatabilty with pages written directly to
          > the CSS/rendering bugs of IE 4, new pages should not be written
          > without a DOCTYPE or with a DOCTYPE that triggers quirks mode.[/color]

          I fully, entirely agree with you.
          [color=blue]
          >
          > Ofcourse, I believe in writing to the official standards. Other people
          > don't care, and will gladly write pages targeted at browsers which can
          > emulate IE4 (currently includes later IEs, Mozilla and Opera 7, and
          > maybe others).
          >
          > These people also live in caves and eat roots (or maybe I am just
          > channeling Dogbert).
          >
          > /L[/color]

          DU
          --
          Javascript and Browser bugs:

          - Resources, help and tips for Netscape 7.x users and Composer
          - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Problem...help

            DU <drunclear@ho t-R-E-M-O-V-E-mail.com> writes:
            [color=blue][color=green]
            > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            > > "http://www.w3.org/TR/html4/transitional.dt d">[/color][/color]

            Should be: "http://www.w3.org/TR/html4/loose.dtd". Doh!
            [color=blue]
            > This will still trigger Safari in backward compatible mode[/color]

            Ick. Do they have to be different from everybody else?
            I would expect that to change at some point.
            [color=blue]
            > and in "almost" standards mode in Mozilla.[/color]

            That is acceptable. IIRC, the only difference between standards and
            almost-standards in Mozilla is how the line-height of block level
            elements affect their inline children.
            [color=blue]
            > Best is to always use a strict DTD with full url (case sensitive):[/color]

            While I prefer to use a strict DTD, some applications need the
            Transitional DTD (mainly those involving frames, since the target
            attribute does not exist in the strict DTD). I rarely use frames, but
            for those who do, I prefer them to use a transitional DTD instead of
            no DTD.

            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Dr John Stockton

              #7
              Re: Problem...help

              JRS: In article <he3b1vcr.fsf@h otpop.com>, seen in
              news:comp.lang. javascript, Lasse Reichstein Nielsen <lrn@hotpop.com >
              posted at Wed, 17 Sep 2003 13:56:52 :-[color=blue]
              >DU <drunclear@ho t-R-E-M-O-V-E-mail.com> writes:
              >[color=green][color=darkred]
              >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
              >> > "http://www.w3.org/TR/html4/transitional.dt d">[/color][/color]
              >
              >Should be: "http://www.w3.org/TR/html4/loose.dtd". Doh![/color]

              W3's off-line tester TIDY is equally happy with a sample of my pages
              whichever of loose.dtd, transitional.dt d, strict.dtd is invoked. It's
              not clear to me whether transitional.dt d exists (I see from <http://www.
              hut.fi/u/hsivonen/doctype.html> that xhtml1-transitional.dt d does,
              elsewhere), but I assume TIDY is not actually using the line.

              I've put datefmts.htm, index.htm, vb-dates.htm, js-date7.htm, and js-
              dates.htm as strict.dtd ; <URL:http://www.merlyn.demon.co.uk/js-
              date7.htm> is probably the most useful test. Does anyone see problems
              with it now using strict.dtd?

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

              Comment

              • Foobus Barrius

                #8
                Re: Problem...help

                On Wed, 17 Sep 2003 19:02:44 +0100, Dr John Stockton
                <spam@merlyn.de mon.co.uk> wrote:
                [color=blue]
                >W3's off-line tester TIDY is equally happy with a sample of my pages
                >whichever of loose.dtd, transitional.dt d, strict.dtd is invoked. It's
                >not clear to me whether transitional.dt d exists (I see from <http://www.
                >hut.fi/u/hsivonen/doctype.html> that xhtml1-transitional.dt d does,
                >elsewhere), but I assume TIDY is not actually using the line.
                >[/color]

                Why guess? Go to the source.


                There is no transitional.dt d, only loose, strict, and frameset.

                I like TIDY for the HTML, but I have terrible problems with it
                mangling JavaScript code.



                -- Foobus

                Quidquid latine dictum sit, altum sonatur.

                Comment

                • Michael Stemper

                  #9
                  Problem...help

                  In article <BB8BB242.42F6% eblinn@sbcgloba l.net>, Ed Blinn <eblinn@sbcglob al.net> writes:[color=blue]
                  >Can someone tell me where the problem here is? I can't get the "squared()"
                  >function to work properly...it supposed to put the squared value into the
                  >iframe area.[/color]

                  You don't actually say what happens, but my guess is that this is the
                  offending line:
                  [color=blue]
                  >parent.squared frame.document. write()[/color]

                  Shouldn't this document.write have an argument?

                  --
                  Michael F. Stemper
                  #include <Standard_Discl aimer>
                  Always use apostrophe's and "quotation marks" properly.

                  Comment

                  • Dr John Stockton

                    #10
                    Re: Problem...help

                    JRS: In article <3h3imvoav3eqn7 rt7qiqn6abr6bhi 6u0nu@4ax.com>, seen in
                    news:comp.lang. javascript, Foobus Barrius <devnull@email. invalid> posted
                    at Thu, 18 Sep 2003 01:55:34 :-[color=blue]
                    >
                    >I like TIDY for the HTML, but I have terrible problems with it
                    >mangling JavaScript code.[/color]

                    Perhaps I should make it clear that I only use it as a checker,
                    preferring to fix faults personally.

                    Once one knows what it wants, one finds that it only finds typos and
                    slip-ups to report - and does so usefully often. I test every page
                    after editing.

                    You could try the effect of putting your javascript within the despised
                    <!-- and --> .

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

                    Comment

                    • Foobus Barrius

                      #11
                      Re: Problem...help

                      On Fri, 19 Sep 2003 20:20:52 +0100, Dr John Stockton
                      <jrs@merlyn.dem on.co.uk> wrote:

                      [color=blue]
                      >
                      >Perhaps I should make it clear that I only use it as a checker,
                      >preferring to fix faults personally.
                      >[/color]

                      I agree, but being a mere mortal I occasionally miss one or two. TIDY,
                      however, manages to find them all, and proceeds to mangle the code
                      accordingly.
                      [color=blue]
                      >You could try the effect of putting your javascript within the despised
                      ><!-- and --> .
                      >[/color]

                      I'm apparently one of the few holdouts that still use those.
                      Unfortunately, TIDY seems to ignore them at times.


                      --

                      Foobus

                      Quidquid latine dictum sit, altum sonatur.

                      Comment

                      • Dr John Stockton

                        #12
                        Re: Problem...help

                        JRS: In article <coenmv0644387b um9t9icabe1gk3k s6db6@4ax.com>, seen in
                        news:comp.lang. javascript, Foobus Barrius <devnull@email. invalid> posted
                        at Sat, 20 Sep 2003 02:31:15 :-[color=blue]
                        >On Fri, 19 Sep 2003 20:20:52 +0100, Dr John Stockton
                        ><jrs@merlyn.de mon.co.uk> wrote:[/color]
                        [color=blue][color=green]
                        >>Perhaps I should make it clear that I only use it as a checker,
                        >>preferring to fix faults personally.
                        >>[/color]
                        >
                        >I agree, but being a mere mortal I occasionally miss one or two. TIDY,
                        >however, manages to find them all, and proceeds to mangle the code
                        >accordingly.[/color]

                        Since TIDY is an offline checker, I always re-test after fixing faults -
                        if only to make the list shorter and easier to work from.

                        It can be worthwhile to look at Tidy's fixes, even if one corrects the
                        master by hand. As a tester, it told me that someone's – was bad.
                        As a fixer, it showed me that &ndash; should work, and the browser shows
                        that it does - also &mdash;.

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

                        Comment

                        Working...