Hi !!! Below is a script which used to sort the data in a table. When u click one of the button, the other data in other column will be sorted. My problem now is the script is too big, i need to reduced the size. I think the most heaviest part is the exchange function which use bubble sort. Can any one give commend to my script in order to reduced the size ???? Thanks !!!!
U may visit this url -->to have a look .
<html>
<head>
<title>Java Script</title>
<SCRIPT LANGUAGE="JavaScript">
function dates(da,db){
return (((d2(da)-d2(db)) < 0) ? 0:1);
}
function d2(d){
return ((d.substring(0,4)*1000)+(d.substring(5,7)*100) +(d.substring(8,10)*1));
}
function exchange(i){
var f = document.forms;
var a = f.check.value;
f.check.value = f[i+1].check.value;
f[i+1].check.value = a;
a = f.units.value;
f.units.value = f[i+1].units.value;
f[i+1].units.value = a;
a = f.amount.value;
f.amount.value = f[i+1].amount.value;
f[i+1].amount.value = a;
a = f.presented.value;
f.presented.value = f[i+1].presented.value;
f[i+1].presented.value = a;
}
function Sort(num)
{
/* orders the table by amount,check number,date,presented */
for (var j = 0; j < 5; j++)
{
for(var i = 0; i < 5; i++)
{
var a = document.forms, b = document.forms[i+1];
if ( ( ( num == 3 ) && ( 1 * a.amount.value > 1 * b.amount.value ) ) ||
( ( num == 2 ) && ( 1 * a.check.value > 1 * b.check.value ) ) ||
( ( num == 1 ) && ( dates ( a.units.value, b.units.value ) ) ) ||
( ( num == 4 ) && ( a.presented.value > b.presented.value ) ) )
{exchange (i);}
}
}
}
</SCRIPT>
</HEAD>
<body>
<center>
<table border=4>
<form method=post>
<tr>
<td><div align=center> <input type="button" value="DATE" onclick=Sort(1)> </div></td>
<td><div align=center> <input type="button" value="CK #" onClick=Sort(2)> </div></td>
<td><div align=center> <input type="button" value="AMOUNT" onClick=Sort(3)> </div></td>
<td><div align=center> <input type="button" value="PAID TO" onClick=Sort(4)> </div></td>
</tr>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units> </td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
</table>
</center>
</body>
</html> [sig][/sig]
U may visit this url -->to have a look .
<html>
<head>
<title>Java Script</title>
<SCRIPT LANGUAGE="JavaScript">
function dates(da,db){
return (((d2(da)-d2(db)) < 0) ? 0:1);
}
function d2(d){
return ((d.substring(0,4)*1000)+(d.substring(5,7)*100) +(d.substring(8,10)*1));
}
function exchange(i){
var f = document.forms;
var a = f.check.value;
f.check.value = f[i+1].check.value;
f[i+1].check.value = a;
a = f.units.value;
f.units.value = f[i+1].units.value;
f[i+1].units.value = a;
a = f.amount.value;
f.amount.value = f[i+1].amount.value;
f[i+1].amount.value = a;
a = f.presented.value;
f.presented.value = f[i+1].presented.value;
f[i+1].presented.value = a;
}
function Sort(num)
{
/* orders the table by amount,check number,date,presented */
for (var j = 0; j < 5; j++)
{
for(var i = 0; i < 5; i++)
{
var a = document.forms, b = document.forms[i+1];
if ( ( ( num == 3 ) && ( 1 * a.amount.value > 1 * b.amount.value ) ) ||
( ( num == 2 ) && ( 1 * a.check.value > 1 * b.check.value ) ) ||
( ( num == 1 ) && ( dates ( a.units.value, b.units.value ) ) ) ||
( ( num == 4 ) && ( a.presented.value > b.presented.value ) ) )
{exchange (i);}
}
}
}
</SCRIPT>
</HEAD>
<body>
<center>
<table border=4>
<form method=post>
<tr>
<td><div align=center> <input type="button" value="DATE" onclick=Sort(1)> </div></td>
<td><div align=center> <input type="button" value="CK #" onClick=Sort(2)> </div></td>
<td><div align=center> <input type="button" value="AMOUNT" onClick=Sort(3)> </div></td>
<td><div align=center> <input type="button" value="PAID TO" onClick=Sort(4)> </div></td>
</tr>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units></td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
<form method=post>
<tr>
<td><input type=text name=units> </td>
<td><input type=text name=check></td>
<td><input type=text name=amount></td>
<td><input type=text name=presented></td>
</tr>
</form>
</table>
</center>
</body>
</html> [sig][/sig]