In the following code I am calculating 2 values when the "Compute
Distance" button is pressed. I would like to find a way to "return" both
value to the form so I can show both when the calculation is made. (one
is merely the doubling of the computed result.)
I have cobbled this form from several places, and I don't remember
enough of HTML or JavaScript to know where to seek additional
information. The code below does the calculation, but the "alerts" have
been my attempt to see what's being done in the function. I have not
actually returned any value to the form - which is my current dilemma: I
can display one value, but I want to display two.
Any thoughts? TIA
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Distances Calculator</TITLE>
<script type="text/javascript">
<!--
var Total = 0.0;
function roundOff(value, precision)
{
value = "" + value //convert value to
string
precision = parseInt(precision);
var whole = "" + Math.round(value * Math.pow(10, precision));
var decPoint = whole.length - precision;
if(decPoint != 0)
{
result = whole.substring(0, decPoint);
result += ".";
result += whole.substring(decPoint, whole.length);
}
else
{
result = whole;
}
return result;
} // roundOff
function Compute(S,E)
{
Distances = new Array(3.90, 4.00, 0.76, 0.48);
var start = S.selectedIndex;
var end = E.selectedIndex;
for (var I = 0; I < Distances.length; I++)
Total = Total+Distances[i];
alert ("Starting @ "+start+" and Ending @ "+end);
Total = 0;
if (start < end)
for (var I = start; I < end; I++)
{
Total = Total+Distances[i];
}
else
for (var I = start; I > end; I--)
{
Total = Total+Distances[i];
}
Total = roundOff(Total, 2);
alert ("Distance = "+Total);
alert("Distance = "+Total+" miles;
Loop = "+(Total*2)+" miles");
return Total;
} // Compute
-->
</script></HEAD>
<BODY leftmargin="0" topmargin="0" marginheight="0" marginwidth="0"
bgcolor="#ffffff" link="#01A9B5" alink="#01A9B5"
vlink="#829899">
<!-- MAIN BODY BEGINS -->
<BODY bgcolor="#ffffff"><A NAME="top">
<TABLE WIDTH=100% BORDER=0>
<tr><TD> </TD></tr>
<tr><TD> </TD></tr>
<TR>
<TD> </TD>
<TD VALIGN="top">
<font size=5 face="Arial, Helv"color="#660066">
<center><B>Distance Calculator</B></center>
</font>
<font size="4" face="Arial, Helv" color="BLUE">
<center>
Use this calculator to compute distance from one point to another.<P>
</font>
<TABLE BORDER=8>
<TR>
<TD>
<TABLE BORDER=0>
<TR>
<TD ALIGN="left"><h3>
<form name="Start">
Start of Run:
<SELECT name="Start_Point">
<OPTION value="0">Granite Reef
<OPTION value="1">Highway 87
<OPTION value="46">Greenway
<OPTION value="47">Western End
</SELECT>
<input type="reset" value="Reset Start">
</form>
</TD>
</TR>
<TR>
<TD ALIGN="left">
<form name="End"><h3>
End of Run/Loop:
<SELECT name="End_Point">
<OPTION value="0">Granite Reef
<OPTION value="1">Highway 87
<OPTION value="46">Greenway
<OPTION value="47">Western End
</SELECT>
<input type="reset" value="Reset End "><P>
<input type="button" value="Compute Distance"
onClick="Compute(document.Start.Start_Point,
document.End.End_Point)">
<input type="input" name="answer" size=11> Miles<BR>
</form>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>
<NOSCRIPT>
Your browser doesn't support JavaScript, so this feature will not
function.
Consider upgrading to a more modern browser.
</NOSCRIPT>
<!-- MAIN BODY ENDS -->
</BODY></HTML>