October 21st, 2002, 05:38 PM

Please Help!! Javascript problem: c squared=a squared*b squared
I need help with this Java Script problem. It is supposed to be able to solve the problem
c*c=a*a=B*b or c squared= a squared*bsquared
and I need the answer to pop up in a new page in a new javascript and have a close tag. (window.close)
I'm so lost...my second wk of javascript in school and I have NO idea what I'm doing. Could anyone please look at my code and help me?
Thanks,
Tracy
Here it is......
<html><head><title>Hypotenuse</title>
<script language="JavaScript">
<!hide from old browsers
document.write("This is JavaScript")
function hypotenuse(){
a=c*c=(document.add.a*a.value)+
(document.add.b*b.value)
alert(a);
function newWindow(open) {
equation = window.open("open", "equation", "width=330,height=250");
equation.focus();
}
//>
</script>
</head>
<body>
<form name="add">
<input type="text" name="a+a" value=""> enter side A.<br>
<input type="text" name="b+b" value=""> enter side B.<br>
<a href="javascript:newWindow(open)"></a>
<input type="button" value="submit"
onClick=" hypotenuse();">
</form>
</body></html>
October 21st, 2002, 07:35 PM

Here is some very basic code to get you going.
Code:
<html><head><title>Hypotenuse</title>
<script language="JavaScript">
<!hide from old browsers
function hypotenuse(){
var a=(document.add.a.value)
var b=(document.add.b.value)
var c = Math.sqrt((a*a)+(b*b))
equation = window.open("open", "equation", "width=330,height=250");
equation.focus();
equation.document.open();
equation.document.write('Hypotenuse = ' + c +'<br><a href="javascript:window.close()">Close this Window</a>');
equation.document.close();
}
//>
</script>
</head>
<body>
<form name="add">
<input type="text" name="a" value=""> enter side A.<br>
<input type="text" name="b" value=""> enter side B.<br>
<input type="button" value="submit"
onClick="hypotenuse();">
</form>
</body></html>
You had some mistakes in your code.
First, name="a+a" is an invalid name, same with b+b
In your script you had document.add.a*a.value
a*a didn't even exist anyway (remember a+a)
You were missing a closing bracket from the hypotenuse() function.
There are much better ways to use mathematical function in javascript, but I'm also learning and have used the basics to get the result into a new window.