PDA

View Full Version : javascript calulator code help



jdgrinder
17 Feb 2011, 08:07 AM
For some reason I can get this to work on my other calculators forms but sometimes it doesn't work. here is the code for the one that doesn't work.

here is the script:

<script language="JavaScript">
<!--
//Script by Tom Richardson Jr.
//Permission to use this scipt is permited as long as this
//part stays intact.
//If you have any questions, e-mail me at gooftroop@geocities.com
//or visit my website at http://home.rmci.net/gooftroop
//This is just a basic calculator that will do the exponential math.
//Or, in basic terms, will calculate powers of any given number.
//Just another user-friendly calculator that uses terms and text
//fields.
//Have fun!!
function calc() {
Pi = 3.1415926535;
a = document.form1.a.value;
b = document.form1.b.value;
c = document.form1.b2.value
d = Pi * (a*a)/4;
e = (b)/231;
f = (d * e);
document.form1.total.value = f;

a2 = document.form1.a.value;
b2 = document.form1.b2.value;
c2 = Pi * (a2*a2)/4;
d2 = Pi * (b2*b2)/4;
e2 = (c2 - d2);
document.form1.total2.value = e2;
f2 = document.form1.total2.value;
g2 = document.form1.b.value;
h2 = (f2 * g2)/231;
document.form1.total222.value = h2
}
//-->
</script>


here is the form code


<form name="form1">
<center>
<table border=2 cellspacing=1 cellpadding=1 width="311" height="343" bordercolorlight="#FF6633" bordercolordark="#CC3333">

<tr bgcolor="#FFCC99">
<td colspan=3 align=center height="40"><font face="Times New Roman, Times, serif" size="3" ><b><h4>Hydraulic
Pump and Motor Displacement in Cubic Inches per Minute</h4></b></font></td>
<tr>
<td height="255" width="94">
<div align="center"><font size="2"><b>Enter GPM<br>
<input type="text" name="a" size=15 maxlength="15">
<br>
</b></font><br>
<b><font size="2">Enter RPM<br>

</font></b>
<input type="text" name="b" size=15 maxlength="15">
</div>
</td>
<td height="255" width="76">
<div align="center"><br>
<br>
<input type="button" value="Calculate" onClick="calc()" name="Calculate"><br><br>
<input type="reset" value="Reset" name="reset">
</div>
</td>

<td height="255" width="118">
<div align="center"><font size="2"><b>Displacement in<br>
CIR</b></font><br>
<input type="text" name="total" size=15 maxlength="15">
</div>
</td>
<tr bgcolor="#FFCC99">
<td colspan=3 align=center height="6">


</td>
</table>
</center>
</form>

I don't understand why it will work for other form calculators I have ? It is the same code on the other ones like the one above?

Thanks

jdgrinder
17 Feb 2011, 11:44 AM
figure it out took me forever but was using the wrong script