Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

swkronenfeld's scratchpad

by swkronenfeld (Hermit)
on Dec 27, 2005 at 22:16 UTC ( #519436=scratchpad: print w/replies, xml ) Need Help??

<script language="javascript"> var browser = 0; function detectBrowser() { var nav = navigator.userAgent; if(nav.indexOf("Firefox") != -1) { browser = 1 } else if(nav.indexOf("MSIE") != -1) { browser = 2 } if(browser) loadTable('alerts'); } var original = new Array(); function loadTable(tableToLoad) { if(!browser) return; var table = document.getElementById(tableToLoad); if(browser == 1) { //Firefox for (i=1; i < table.rows.length; i++) original[i] = table.rows +[i].innerHTML; } else if(browser == 2) { // MSIE for (i=1; i < table.rows.length; i++) { original[i] = new Array(table.rows[i].cells.length); for (j=0; j < table.rows[i].cells.length; j++) { original[i][j] = table.rows[i].cells[j].innerText; } } } } function sortNumeric(a,b) { return b-a } var fw = new Array("bold","bold","","","","",""); var bgColor = new Array("green","green","gray","gray","red","orange"," +yellow"); function sortTable(tableToSort, col) { if(!browser) return; var table = document.getElementById(tableToSort); var tabRows = new Array(); var hash = new Array(); var i; //Load the data into an array and hash table for (i=1; i < table.rows.length; i++) { tabRows[i-1] = table.rows[i].cells[col].innerHTML; if(!hash[tabRows[i-1]]) { hash[tabRows[i-1]] = new Array(); } hash[tabRows[i-1]][hash[tabRows[i-1]].length] = i; } //Now sort the array, columns higher than col 1 are numeric data if(col > 1) { tabRows.sort(sortNumeric) } else { tabRows.sort() } //Print out the sorted array var len = table.rows.length; var last; var count; for(i=len-1; i>0; i--) table.deleteRow(i); //kill the table excep +t header for(i=0; i<len-1; i++) { var tmp = tabRows[i]; if(tmp==last) { count++; } else { count = 0; } last = tmp; var r = table.insertRow(i+1); if(browser == 1) { //Firefox r.innerHTML = original[hash[tabRows[i]][count]]; } else if(browser == 2) { //MSIE for (j=0; j<7; j++) { var c = r.insertCell(j); c.innerText = original[hash[tabRows[i]][count]][j]; c.bgColor=bgColor[j]; c.style.fontWeight = fw[j]; } } } loadTable(tableToSort); } </script>
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2021-03-08 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (128 votes). Check out past polls.

    Notices?