473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Return 2 Values from Function

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">
&nbsp;Start of Run:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<SELECT name="Start_Point">
<OPTION value="0">Granite Reef
<OPTION value="1">Highway 87
<OPTION value="46">Greenway
<OPTION value="47">Western End
</SELECT>
&nbsp;&nbsp;<input type="reset" value="Reset Start">
</form>
</TD>
</TR>
<TR>
<TD ALIGN="left">
<form name="End"><h3>
&nbsp;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>
&nbsp;&nbsp;<input type="reset" value="Reset End&nbsp;"><P>
<input type="button" value="Compute Distance"
onClick="Compute(document.Start.Start_Point,
document.End.End_Point)">
&nbsp;&nbsp;
<input type="input" name="answer" size=11>&nbsp;&nbsp;&nbsp;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>
Jul 20 '05 #1
0 3419

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

66
by: Darren Dale | last post by:
Hello, def test(data): i = ? This is the line I have trouble with if i==1: return data else: return data a,b,c,d = test()
3
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
5
by: Petr Bravenec | last post by:
I have found that when I use the RETURN NEXT command in recursive function, not all records are returned. The only records I can obtain from function are records from the highest level of...
8
by: Ravindranath Gummadidala | last post by:
Hi All: I am trying to understand the C function call mechanism. Please bear with me as I state what I know: "every invocation of a function causes a frame for that function to be pushed on...
5
by: D. Shane Fowlkes | last post by:
This may be a very basic question but it's something I've never done before. I've looked at a couple of my favorite sites and books and can't find an answer either. I can write a Function to...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
8
by: aleksandar.ristovski | last post by:
Hello all, I have been thinking about a possible extension to C/C++ syntax. The current syntax allows declaring a function that returns a value: int foo(); however, if I were to return...
80
by: xicloid | last post by:
I'm making a function that checks the input integer and returns the value if it is a prime number. If the integer is not a prime number, then the function should return nothing. Problem is, I...
4
by: barcaroller | last post by:
I am trying to adopt a model for calling functions and checking their return values. I'm following Scott Meyer's recommendation of not over-using exceptions because of their potential overhead. ...
2
ADezii
by: ADezii | last post by:
The incentive for this Tip was an Article by the amazing Allen Browne - I considered it noteworthy enough to post as The Tip of the Week in this Access Forum. Original Article by Allen Browne ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.