Click to See Complete Forum and Search --> : A math comparing question....


sciguyryan
10-02-2003, 10:19 AM
could someone give me a code to do this....

6 input text fields with a sum or value in each ,
then when a button is clicked then the results of the sum are put into the order of their size defined by the user( from highest to lowest or vice versa) onto the current document.

if you could provide a code for this i would be most greatfull.
thank you in advance.

AdamBrill
10-02-2003, 12:32 PM
The easiest way would probably be to create an array and sort it. Like this:<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function sort(){
test = new Array();
test[0] = document.form1.num1.value;
test[1] = document.form1.num2.value;
test[2] = document.form1.num3.value;
test[3] = document.form1.num4.value;
test[4] = document.form1.num5.value;
test[5] = document.form1.num6.value;
test = test.sort();
document.getElementById('sorted').innerHTML=test;
}
</script>
</head>
<body>
<form name="form1">
<input type="text" name="num1"><br>
<input type="text" name="num2"><br>
<input type="text" name="num3"><br>
<input type="text" name="num4"><br>
<input type="text" name="num5"><br>
<input type="text" name="num6"><br>
<input type="button" onclick="sort()">
</form>
<p>
<div id="sorted"></div>
</p>
</body>
</html>

sciguyryan
10-02-2003, 01:36 PM
whoo, yea i owe you ane Adam!

AdamBrill
10-02-2003, 02:57 PM
lol, I'm glad to help. ;)