i’m using javascript, below is the form. If you go to the(A * B / C * D); part of the form. For some reason it does not work…do not know if I have something wrong. But if I were to enter 30 as A, 100,000 as B, 6 as C, and .2 as D. The answer should be 10,000. Can you help me figure out what is wrong?
<!-- 2005/11/08 Science Buddies: JavaScript calculator, adds two numbers -->
<HTML>
<HEAD>
<TITLE>Simple Adder</TITLE>
<!-- saved from url=(0030)[url]http://www.sciencebuddies.org/[/url] -->
<!-- When this code is saved as a local file, the preceding line tells Internet Explorer to treat this file according to the security rules for the Internet zone (plus any security rules specific for the Science Buddies website). -->
<SCRIPT LANGUAGE="JavaScript">
<!-- old browsers can't handle JavaScript functions so comment them out
// This is a single-line JavaScript comment.
// Below is a multi-line JavaScript comment.
/* CalculateSum: this function has 3 arguments:
Atext, Btext and form. It converts Atext and Btext to
numbers using the built-in JavaScript "parseFloat" method.
It then uses the form argument to output the sum of the
numbers to the form's Answer field. Notice that the
function does *not* need to know the the names of the
form's input fields. Those values are passed as arguments.
It does need to know that the form has a field named
"Answer" so that it can put the result there.
Here is how to end a multi-line JavaScript comment: */
function CalculateSum(Atext, Btext, Ctext, Dtext, form)
{
var A = parseFloat(Atext);
var B = parseFloat(Btext);
var C = parseFloat(Ctext);
var D = parseFloat(Ctext);
form.Answer.value = (A * B / C * D);
}
/* ClearForm: this function has 1 argument: form.
It clears the input and answer fields on the form.
It needs to know the names of the INPUT elements in order
to do this. */
function ClearForm(form)
{
form.input_A.value = "";
form.input_B.value = "";
form.input_C.value = "";
form.input_D.value = "";
form.Answer.value = "";
}
// end of JavaScript functions -->
</SCRIPT>
</HEAD>
<BODY>
<P><FONT SIZE="+2">Simple Adder</FONT></P>
<FORM NAME="Calculator" METHOD="post">
<P>Enter the number of SCR trucks you operate: <INPUT TYPE=TEXT NAME="input_A" SIZE=10></P>
<P>Enter the average miles for a single truck, traveled in one year (default is 100,000 miles p.a.): <INPUT TYPE=TEXT NAME="input_B" SIZE=10></P>
<P>Enter the average fuel mileage of your trucks (measured as MPG, defaults is 6 MPG): <INPUT TYPE=TEXT NAME="input_C" SIZE=10></P>
<P>Default dosage rate is 2% DEF per every gallon of diesel fuel based on engine manufactures: <INPUT TYPE=TEXT NAME="input_D" SIZE=10></P>
<P><INPUT TYPE="button" VALUE="Average yearly gallons of DEF you may consume" name="AddButton" onClick="CalculateSum(this.form.input_A.value, this.form.input_B.value, this.form.input_C.value, this.form.input_D.value, this.form)"></P>
<P><INPUT TYPE="button" VALUE="Clear Fields" name="ClearButton" onClick="ClearForm(this.form)"></P>
<P>Answer = <INPUT TYPE=TEXT NAME="Answer" SIZE=12></P>
</FORM>
</BODY>
</HTML>
</html>