Problem...help

E

Ed Blinn

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

Lasse Reichstein Nielsen

Ed Blinn said:
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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
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).
 
L

Lasse Reichstein Nielsen

Dr John Stockton said:
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:
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
 
D

DU

Lasse said:
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:



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
 
L

Lasse Reichstein Nielsen

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:

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

Foobus Barrius

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

Michael Stemper

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

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
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 --> .
 
F

Foobus Barrius

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

Dr John Stockton

JRS: In article <[email protected]>, seen in
news:comp.lang.javascript said:
On Fri, 19 Sep 2003 20:20:52 +0100, Dr John Stockton


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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top