Ok, here’s what I’m trying to do. I must admit I’m a bit of a javascript novice though, I want to dynamically re-write a portion of a page (table contents) on the fly. Basically I want to be able to sort the contents of a table, and only re-write that particular part.
The document.write function appears to re-write the entire page. I can sort the contents fine, its the writing to the page I can’t figure out. Here’s the code I’ve written so far, I’d appreciate any javascript advice
<HTML>
<HEAD>
<TITLE> TEST HTML FOR JAVASCRIPT FUNCTIONS - ARRAY SORTING</TITLE>
<SCRIPT LANGUAGE="javascript">
myArray = new Array ("100", "10", "26", "600", "403")
function desc (a, b)
{
return b - a;
}
function asc (a, b)
{
return a - b;
}
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="javascript">
function sort(what)
{
if (what == "up"){
myArray.sort(asc)
}
if (what == "down"){
myArray.sort(desc)
}
for (i=0; i < myArray.length; i++)
{
document.write("<TABLE WIDTH=500 border=1><TR>")
document.write("<TD>" + myArray* + "</TD>")
document.write("</TR></TABLE>")
}
}
sort('up')
</SCRIPT>
<INPUT type="button" name="ASC" value="ASC" onClick="sort('up')">
<INPUT type="button" name="DESC" value="DESC" onClick="sort('down')">
</BODY>
</HTML>