473,241 Members | 1,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,241 software developers and data experts.

Problem - part 2

Can someone tell me why this script will only work on a Mac with Internet
Explorer.

Thanks,
Ed

<html>
<head>
<script type="text/javascript">
//Square Root
function squareroot()
{
var x=document.forms('root')
var data=x.elements['num'].value;
var sqr=Math.sqrt(data)
frames['sqrt'].document.write(sqr)
}
//Squared of an item
function squared()
{
var x=document.forms('square')
var data=x.elements['num2'].value;
var sum=data*data
frames['squaredframe'].document.write(sum)
}
//Tanget
function tangent()
{
var x=document.forms('tangent')
var data=x.elements['num3'].value;
var tan=Math.tan(data)
frames['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="num" 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="num2" 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="num3" 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>

Jul 20 '05 #1
1 2052
DU
Ed Blinn wrote:
Can someone tell me why this script will only work on a Mac with Internet
Explorer.

Thanks,
Ed

<html>
No doctype declaration.
http://www.hut.fi/u/hsivonen/doctype.html
http://www.w3.org/QA/2002/04/valid-dtd-list.html
<head>
<script type="text/javascript">
//Square Root
function squareroot()
{
var x=document.forms('root')
1- When editing any kind of code in any language, try to use meaningful,
intuitive, significant identifier names for variables. This is a good
coding practice which saves time to others reviewing your code, help
debugging with debuggers, etc..
2- forms["root"] is correct. forms[0] is even better since it will work
flawlessly in HTML strict DTD and XHTML strict DTD. forms('root') won't
work.

Together:

var objForm = document.forms["root"];
var data=x.elements['num'].value;
W3C DOM methods prefer
elements.namedItem("num").value

http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-76728479
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-75708506
http://www.w3.org/TR/DOM-Level-2-HTM...tion-namedItem

var sqr=Math.sqrt(data)
If data is a string, then calling Math.sqrt will not work... and num is
type="text"
http://devedge.netscape.com/library/...h.html#1197825
frames['sqrt'].document.write(sqr)
You must first open the iframed document, then write sqr, then close the
iframed document.

So:

frames["sqrt"].document.open();
"open:
Open a document stream for writing. If a document exists in the
target, this method clears it."
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-72161170
frames["sqrt"].document.write(sqr);
frames["sqrt"].document.close();

"close:
Closes a document stream opened by open() and forces rendering."
http://www.w3.org/TR/DOM-Level-2-HTM...ml#ID-98948567

IMO, there is nothing, absolutely nothing which justifies the use of
iframes for the apparent purposes of your code.
}
//Squared of an item
function squared()
{
var x=document.forms('square')
var objFormSquare = document.forms["square"];
var data=x.elements['num2'].value;
var data = parseFloat(objFormSquare.elements.namedItem("num2" ).value);
var sum=data*data
frames['squaredframe'].document.write(sum)
open and close here too.
}
//Tanget
function tangent()
{
var x=document.forms('tangent')
forms["FormName"] or forms[index]
var data=x.elements['num3'].value;
var tan=Math.tan(data)
Again here too: parseFloat before calculating the tan.
The parameter must be a number.
http://devedge.netscape.com/library/...h.html#1194346
frames['tangentframe'].document.write(tan)
}
//Refresh Values
function refresh()
{
location.reload(sqrt)
frames["sqrt"].location.reload(true);
would be the correct way to force a reload but since you would open()
and then close() the iframe, then reloading the iframed document is no
longer necessary.
location.reload(squaredframe)
location.reload(tangentframe)
}
</script>
</head>

<body>
<table width="100%" border="1">
table design: avoid this whenever you can. Tables should be used only
for tabular data.
<tr>
<td width="73%" height="50">
<form name="root">
A table can be inside a form; the opposite creates invalid documents.
Here, the action attribute is missing. A validator would have reported
this as an error.
Type in a number to compute the square root of the value.
<input name="num" type="text" id="num" size="10" maxlength="10">
For several reasons which I won,t explicit here, I recommend to always
give distinct identifier values to name attribute and id attribute. If
you don't need to declare an id attribute, then don't.
<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">
same thing here: you can not have a form inside a table. Action missing.
Type in a number to compute the square of the value.
<input name="num2" 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">
action missing; form can not be within a table.
Type in a number to compute the tanget of the value.
<input name="num3" 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>


3 forms, 3 iframes, reload/refresh functions can be reduced to, replaced
by a single form.

Tested, valid and working in MSIE 6 for Windows, Opera 7.20, Mozilla
1.5b and NS 7.1:

http://www10.brinkster.com/doctorunc...culations.html

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/doctorunc...e7Section.html

Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Marc | last post by:
Hi all, I was using Tkinter.IntVar() to store values from a large list of parts that I pulled from a list. This is the code to initialize the instances: def initVariables(self): self.e =...
4
by: fis | last post by:
Hi all, I've problem because there are needed break lines in my texts on the web site but i can't do it :( My pipeline looks like: XMS -> I18N -> XSLT -> HTML I have lot of texts in my...
6
by: Nafai | last post by:
Hello. I want to do something like this: class A { // It's virtual protected: float* data; int n; public: A(int a); virtual float* createData(); //...
17
by: Jon Slaughter | last post by:
I'm having a little trouble understanding what the slicing problem is. In B.S.'s C++ PL3rdEd he says "Becayse the Employee copy functions do not know anything about Managers, only the Employee...
0
by: umhlali | last post by:
I get the following exception when my VB.NET app calls a Java web service that returns an array of objects. The same call works for a single object though. So looks like there is no problem...
1
by: caldera | last post by:
hi, I have a debug problem. I divide my web project into two part actually two project. One part is include the all of the logic class and other part web application part. These are two different...
11
by: Siv | last post by:
Hi, I seem to be having a problem with a DataAdapter against an Access database. My app deletes 3 records runs a da.update(dt) where dt is a data.Datatable. I then proceed to update a list to...
2
by: yqlu | last post by:
I hava developed a client in C# that is connected to a 3-party XML Web Services developed in Java based on the AXIS 1.1. Most methods call are successful except for one method named "findObjects"...
1
by: leslie_tighe | last post by:
Hello, I have webservice created with Axis 1.2.1 and that I am trying to consuming in .NET (VB) using the Microsoft provided tools. While I am able to consume methods on the service that return...
4
by: leslie_tighe | last post by:
Hello, I have a webservice running on a J2EE server created with Axis 1.2.. I have a client that I am building in .net that needs to consume this webserivce and am having a bit of trouble. I have...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.