Problem...help

Discussion in 'Javascript' started by Ed Blinn, Sep 16, 2003.

  1. Ed Blinn

    Ed Blinn Guest

    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.value
    var sqr=Math.sqrt(data)
    parent.sqrt.document.write(sqr)
    }
    //Squared of an item
    function squared()
    {
    x=document.square
    data=x.num.value
    var sum=data*data
    parent.squaredframe.document.write()
    }
    //Tanget
    function tangent()
    {
    x=document.tangent
    data=x.num.value
    var tan=Math.tan(data)
    parent.tangentframe.document.write(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="squareroot()"
    value="Compute">
    </form></td>
    <td width="27%" height="50"><iframe 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="squared()"
    value="Compute">
    </form></td>
    <td><iframe name="squaredframe" 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="tangent()"
    value="Compute">
    </form></td>
    <td><iframe name="tangentframe" 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="refresh()" value="Refresh Values">
    </form>
    </div>
    </body>
    </html>
    Ed Blinn, Sep 16, 2003
    #1
    1. Advertising

  2. Ed Blinn <> writes:

    > 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.


    Does the other functions work? (No, not in my browsers)

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


    This DOCTYPE triggers quirks mode. New pages should not be made for
    quirks mode.

    > function squareroot()
    > {
    > x=document.root


    I prefer
    var x = document.forms['root'];

    > data=x.num.value


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

    It is much easier to read, and is guaranteed to work in all W3C DOM
    browsers too.

    > var sqr=Math.sqrt(data)


    Why make "sqr" a local variable, but not "x" or "data"?

    > parent.sqrt.document.write(sqr)


    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);

    > function squared()
    > {
    > x=document.square
    > data=x.num.value


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

    ....
    > <form name="square">

    ....
    > <input name="num3" type="text" id="num2" size="10" maxlength="10">


    /L
    --
    Lasse Reichstein Nielsen -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 16, 2003
    #2
    1. Advertising

  3. JRS: In article <>, seen in
    news:comp.lang.javascript, Lasse Reichstein Nielsen <>
    posted at Tue, 16 Sep 2003 02:32:17 :-
    >
    >> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

    >
    >This DOCTYPE triggers quirks mode. New pages should not be made for
    >quirks mode.


    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.demon.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
    Dr John Stockton, Sep 16, 2003
    #3
  4. Dr John Stockton <> writes:

    > >This DOCTYPE triggers quirks mode. New pages should not be made for
    > >quirks mode.

    >
    > What, then, do you recommend?


    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.dtd">

    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/>

    > 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).


    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 -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 16, 2003
    #4
  5. Ed Blinn

    DU Guest

    Lasse Reichstein Nielsen wrote:
    > Dr John Stockton <> writes:
    >
    >
    >>>This DOCTYPE triggers quirks mode. New pages should not be made for
    >>>quirks mode.

    >>
    >>What, then, do you recommend?

    >
    >
    > 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.dtd">
    >
    > If in doubt, add the appropriate URL for the DTD, that always gives
    > standards mode.
    >


    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">

    http://www.hut.fi/u/hsivonen/doctype.html

    > Opera's page about it, with links to MSDN and Mozilla:
    > <URL:http://www.opera.com/docs/specs/doctype/>
    >
    >>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).

    >
    >
    > 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.


    I fully, entirely agree with you.

    >
    > 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


    DU
    --
    Javascript and Browser bugs:
    http://www10.brinkster.com/doctorunclear/
    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
    http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
    DU, Sep 17, 2003
    #5
  6. DU <> writes:

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


    Should be: "http://www.w3.org/TR/html4/loose.dtd". Doh!

    > This will still trigger Safari in backward compatible mode


    Ick. Do they have to be different from everybody else?
    I would expect that to change at some point.

    > and in "almost" standards mode in Mozilla.


    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.

    > Best is to always use a strict DTD with full url (case sensitive):


    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 -
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
    'Faith without judgement merely degrades the spirit divine.'
    Lasse Reichstein Nielsen, Sep 17, 2003
    #6
  7. JRS: In article <>, seen in
    news:comp.lang.javascript, Lasse Reichstein Nielsen <>
    posted at Wed, 17 Sep 2003 13:56:52 :-
    >DU <> writes:
    >
    >> > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    >> > "http://www.w3.org/TR/html4/transitional.dtd">

    >
    >Should be: "http://www.w3.org/TR/html4/loose.dtd". Doh!


    W3's off-line tester TIDY is equally happy with a sample of my pages
    whichever of loose.dtd, transitional.dtd, strict.dtd is invoked. It's
    not clear to me whether transitional.dtd exists (I see from <http://www.
    hut.fi/u/hsivonen/doctype.html> that xhtml1-transitional.dtd 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.demon.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
    Dr John Stockton, Sep 17, 2003
    #7
  8. On Wed, 17 Sep 2003 19:02:44 +0100, Dr John Stockton
    <> wrote:

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


    Why guess? Go to the source.
    http://www.w3.org/QA/2002/04/valid-dtd-list.html

    There is no transitional.dtd, 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.
    Foobus Barrius, Sep 18, 2003
    #8
  9. In article <BB8BB242.42F6%>, Ed Blinn <> writes:
    >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.


    You don't actually say what happens, but my guess is that this is the
    offending line:

    >parent.squaredframe.document.write()


    Shouldn't this document.write have an argument?

    --
    Michael F. Stemper
    #include <Standard_Disclaimer>
    Always use apostrophe's and "quotation marks" properly.
    Michael Stemper, Sep 19, 2003
    #9
  10. JRS: In article <>, seen in
    news:comp.lang.javascript, Foobus Barrius <> posted
    at Thu, 18 Sep 2003 01:55:34 :-
    >
    >I like TIDY for the HTML, but I have terrible problems with it
    >mangling JavaScript code.


    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.demon.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
    Dr John Stockton, Sep 19, 2003
    #10
  11. On Fri, 19 Sep 2003 20:20:52 +0100, Dr John Stockton
    <> wrote:


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


    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.

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


    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.
    Foobus Barrius, Sep 20, 2003
    #11
  12. JRS: In article <>, seen in
    news:comp.lang.javascript, Foobus Barrius <> posted
    at Sat, 20 Sep 2003 02:31:15 :-
    >On Fri, 19 Sep 2003 20:20:52 +0100, Dr John Stockton
    ><> wrote:


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

    >
    >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.


    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.demon.co.uk/js-index.htm> JS maths, dates, sources.
    <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
    Dr John Stockton, Sep 20, 2003
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?dHJlbGxvdzQyMg==?=

    HELP! HELP! HELP! Opening Web Application Project Error

    =?Utf-8?B?dHJlbGxvdzQyMg==?=, Feb 20, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    745
    =?Utf-8?B?dHJlbGxvdzQyMg==?=
    Feb 20, 2004
  2. Harvey
    Replies:
    0
    Views:
    676
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    823
    Daniel
    Jul 16, 2004
  4. =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=

    HELP - HELP - HELP

    =?Utf-8?B?S2ltb24gSWZhbnRpZGlz?=, Mar 9, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    668
    Eliyahu Goldin
    Mar 9, 2006
  5. Mike

    Problem problem problem :( Need Help

    Mike, May 7, 2004, in forum: ASP General
    Replies:
    2
    Views:
    534
    Bullschmidt
    May 11, 2004
Loading...

Share This Page