Click to See Complete Forum and Search --> : simple calculator


96turnerri
09-17-2003, 06:58 AM
hi im after a simple calaculator with two different items, you can enter a value in either box when press calculate it calculates the other one lets say the left box = a and the right = b

a=cuberoot of b
b=a^3

also i would like a reset/clear button on it

i have tried to modify a couple that i have seen without much luck :( , can you please help me.

Thanks
Rich

Khalid Ali
09-17-2003, 08:17 AM
post your modified piece of code...

AdamGundry
09-17-2003, 10:45 AM
How about this:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Cube and Cube Root</title>
<script type="text/javascript">
function calcCube(){
// By Adam Gundry
a = document.cube.valueA.value;
b = document.cube.valueB.value;

if (a != ''){
if (b != ''){
alert('Please leave one box empty!');
} else {
b = Math.pow(a, 3);
}
} else if (b != ''){
a = Math.pow(b, 1/3);
} else {
alert('Please enter a value in one of the boxes!');
}

document.cube.valueA.value = a;
document.cube.valueB.value = b;
return false;
}
</script>
</head>
<body>
<form name="cube" onsubmit="return calcCube()">
<p>Value A: <input type="text" name="valueA">
<p>Value B: <input type="text" name="valueB">
<p><button type="submit">Calculate</button> <button type="reset">Reset</button>
</form>
</body>
</html>
Adam

jalarie
09-18-2003, 09:59 AM
Change your "<button..." line to:

&nbsp;<input type="submit" value="Calculate"> <input type="reset" value="Reset">

pyro
09-18-2003, 10:05 AM
Why? :confused:

jalarie
09-18-2003, 10:08 AM
Because then it works.

pyro
09-18-2003, 10:48 AM
It will work fine how Adam Gundry posted it in all browsers that aren't from the stone age...

jalarie
09-18-2003, 11:49 AM
1. I neglected to look at the poster name and jumped to the conclusion that Adam's post was 96turnerri's response to Khalid Ali's request to, "post your modified piece of code...." Sorry; my mistake.
2. Since Adam's example does work in all "modern" browsers, I should probably just shut up at this point. But I've already posted a response, so: Mine works in new AND old ones. :D

AdamGundry
09-19-2003, 02:39 PM
LOL. I'd say if your browser can't understand standard HTML 4.01, it's time to get a new browser. But that would require all MSIE users to upgrade to Mozilla, Opera, Konqueror or another compliant browser. :D

Adam

pyro
09-19-2003, 03:07 PM
Originally posted by AdamGundry
But that would require all MSIE users to upgrade to Mozilla, Opera, Konqueror or another compliant browser.Would that be a bad thing? ;)

AdamGundry
09-20-2003, 03:08 AM
<sigh>No, just an improbable one.</sigh>

Adam