0

Below is my code, I have two problems.
1. I would like to remove the E with the box from the webscreen. Is there a way to do this without messing up the calculations?
2. Would like question 2 and the answer to have a , . Example want 100,000 and not 100000.

<html>
<head>
<script type="text/javascript">
function CalculateSum(form)

{
Atext=form.input_A.value;
Btext=form.input_B.value;
Ctext=form.input_C.value;
Dtext=form.input_D.value;
Etext=form.input_E.value;
var A = parseFloat(Atext);
var B = parseFloat(Btext);
var C = parseFloat(Ctext);
var D = parseFloat(Dtext);
var E =parseFloat(Etext);
if(E<300)
form.Answer_for_E.value="Jugs";
else
if((E>=300) && (E<800))
form.Answer_for_E.value="Drums";
else
if((E>=800) && (E<6601))
form.Answer_for_E.value="IBC";
else
form.Answer_for_E.value="Bulk";
form.Answer.value = (A * B / C * D);

}
</script>
</head>
<body>
<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' value='100000'></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' value='6'></p>

<P style="margin-top: 0; margin-bottom: 0">Default dosage rate is 2% DEF per every gallon of diesel fuel based on engine manufactures: <input type='text' name="input_D" size='10' value=.02></p>
<p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(Please enter percent as a decimal. ie 2% is entered as .02) </p>
<p>E<INPUT TYPE=TEXT NAME="input_E" SIZE=10>
<P><INPUT TYPE="button" VALUE="Average yearly gallons of DEF you may consume:" name="AddButton" onClick="CalculateSum(this.form)">
  <input name='Answer' type=text value"gallons comsumed" size="20">
<p>Recommended form of package to be used when ordering DEF: 
<input name='Answer_for_E' type=text value"here will be the answer for E" size="20">

<P><INPUT TYPE="reset" VALUE="Clear Fields" name="ClearButton"></P>



</FORM>



</BODY>

</HTML>
2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by mcrawford3911
0

Mcrawford3911,

HTML supports hidden fields, which are invisible to the user but are addressable by javascript and get submitted with the rest of the form.

<input type="hidden" name="input_e" size="10" />

This function returns a string version of a number with commas added to the left of a decimal point (if present). You can pass to it an integer or float or string representations of integer or float. It is tolerant of alhabetic characters accidentally passed.

function addcommas( val ){
	var parts = (''+val).split('.');//Make sure value is a string and split at decimal point (if present) into array.
	var pattern = new RegExp('(-?[0-9]+)([0-9]{3})');
	while(pattern.test(parts[0])) { parts[0] = parts[0].replace(pattern, '$1,$2'); }//Add thousands separators only to the part found left of decimal point, or whole string if no dp present.
	return parts.join('.');//Put decimal parts back together and return.
}

This is a modified version of something I found here, with credit to joshie76.

Airshow

Edited by Airshow: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.