JavaScript
--
Questions
--
Followers
Top Experts
but with arrows in all columns
suppose i have a table with 2 columns name and age
initially i have one arrow which is clickable on the name column(on page load name column is sorted) and there is an arrow which is disabled in the age column
now when i click the age column i want the arrow in the age column enabled and the arrow in the name column disabled...
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
Do you need three state arrows?
What are your requirments for sorting features? What is the regular content of a table cell?
Or is this question only for switching images? That would be trivial.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
can u modify ur script here http://www.geocities.com/ameba_vb/qpost/hof.html
to just include arrows in all columns...
disable arrows in inactive columns..?

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
I merged css, js and the html all into one file for clarity, but you better separate them into different files.
Here the complette example:
<html>
<head>
<title>Zvonko *</title>
<style>
body {font-family:arial,Verdana
#hof {border:solid; border-color:#000000; border-width:1;font-size:x
#hof tr.hdr {background-color:#cccccc;
#hof tr.odd {background-color:#eeeeee;
#hof tr.evn {background-color:#dddddd;
#hof tr {background-color:#eeeeee;
#hof th {padding-right: 10px; background-position: center right; background-repeat: no-repeat;}
th.srtasc {background-image:url('https://www.experts-exchange.com/mW.gif');}
th.srtdsc {background-image:url('https://www.experts-exchange.com/mO.gif');}
tr.ovr {background-color:#ddeeee;
td {text-align: center;}
</style>
<script>
//zpSortHOF.js
var selectedColor = "blue";
var defaultColor = "black";
function initTable(tabName, sortRules){
 hdrRows = 1;
 numeric = '..';
 desc = '..';
 html = '..';
 for(rule in sortRules){
  window[rule] = sortRules[rule];
 }
 var theTab = document.getElementById(ta
 for(r=0;r<hdrRows;r++)
  for(c=0;c<theTab.rows[r].c
   if((r+theTab.rows[r].cells
    hdrRows=r+theTab.rows[r].c
 for(r=0;r<hdrRows; r++){
  colNum = 0;
  for(c=0;c<theTab.rows[r].c
   if(theTab.rows[r].cells[c]
    theCell = theTab.rows[r].cells[c];
    rTitle = theCell.innerHTML.replace(
    if(rTitle>""){
     theCell.title = rTitle;
     theCell.onmouseover = function(){setCursor(this,
     theCell.onmouseout = function(){setCursor(this,
     var sortParams = 7;
     if(numeric.indexOf("."+col
     if(desc.indexOf("."+colNum
     if(html.indexOf("."+colNum
     theCell.onclick = new Function("sortTable(this,"
    }
   } else {
    colNum = colNum+theTab.rows[r].cell
   }
  }
 }
}
function setCursor(theCell, mode){
 rTitle = theCell.innerHTML.replace(
 if(mode=="selected"){
  if(theCell.style.color!=se
   defaultColor = theCell.style.color;
  theCell.style.color = selectedColor;
  theCell.style.cursor = "hand";
  window.status = "Click to sort by '"+rTitle+"'";
 } else {
  theCell.style.color = defaultColor;
  theCell.style.cursor = "";
  window.status = "";
 }
}
var sortCell;
function sortTable(theCell, colNum, hdrRows, sortParams){
 var num = !(sortParams & 1);
 sDir = !(sortParams & 2);
 var html = !(sortParams & 4);
 var tBody = theCell.parentNode;
 while(tBody.nodeName!="TBO
  tBody = tBody.parentNode;
 }
 if(sortCell) sortCell.className="";
 var tabOrd = new Array();
 if(tBody.rows[0].sCol==col
 tBody.rows[0].sCol = colNum;
 tBody.rows[0].sDir = sDir;
 sortCell=theCell;
 theCell.className=(sDir)?"
 for(i=0,r=hdrRows;r<tBody.
  colCont = tBody.rows[r].cells[colNum
  if(html) colCont = colCont.replace(/<[^>]+>/g
  if(num) {
   colCont*=1;
   if(isNaN(colCont)) colCont = 0;
  }
  tabOrd[i] = [r, tBody.rows[r], colCont];
 }
 tabOrd.sort(compRows);
 for(i=0,r=hdrRows;r<tBody.
  tBody.insertBefore(tabOrd[
  tBody.rows[i].className = (i%2)?"odd":"evn";
 }
 for(i=0;i<hdrRows;i++){
  tBody.rows[i].className = "hdr";
 }
 window.status = "";
}
function compRows(a, b){
 if(sDir){
  if(a[2]>b[2]) return -1;
  if(a[2]<b[2]) return 1;
 } else {
  if(a[2]>b[2]) return 1;
  if(a[2]<b[2]) return -1;
 }
 return 0;
}
function rowHigh(e){
 var theRow = (e.srcElement)?e.srcElemen
 while(theRow&&theRow.nodeN
  theRow=theRow.parentNode;
 }
 if(theRow&&theRow.classNam
  if(e.type.indexOf("over")>
   theRow.oldClass = theRow.className;
   theRow.className = "ovr";
  } else {
   theRow.className = theRow.oldClass;
  }
 }
}
</script>
</head>
<body bgcolor="#e8f0f8" onLoad='initTable("hof", {hdrRows:1, numeric:".1.", desc:".2." });'>
<center>
<table id="hof" bgcolor="#ffffff" onmouseover="rowHigh(event
<tr class="hdr">
<th>Member</th>
<th>Points</th>
<th>Registration</th>
</tr>
<TR>
<TD>Zvonko</TD>
<TD>961172</TD>
<TD>1997/01/05</TD>
</TR>
<TR class="evn">
<TD>archrajan</TD>
<TD>960862</TD>
<TD>2004/10/04</TD>
</TR>
<TR>
<TD>Batalf</TD>
<TD>789335</TD>
<TD>1999/05/19</TD>
</TR>
<TR class="evn">
<TD>GwynforWeb</TD>
<TD>382872</TD>
<TD>2002/12/25</TD>
</TR>
<TR>
<TD>mplungjan</TD>
<TD>337955</TD>
<TD>1998/04/06</TD>
</TR>
<TR class="evn">
<TD>amit_g</TD>
<TD>257888</TD>
<TD>2003/04/15</TD>
</TR>
<TR>
<TD>ldbkutty</TD>
<TD>232751</TD>
<TD>2004/04/26</TD>
</TR>
<TR class="evn">
<TD>WoodyRoundUp</TD>
<TD>171242</TD>
<TD>2000/11/30</TD>
</TR>
<TR>
<TD>justinbillig</TD>
<TD>153519</TD>
<TD>2004/05/10</TD>
</TR>
<TR class="evn">
<TD>devic</TD>
<TD>151639</TD>
<TD>2003/08/26</TD>
</TR>
<TR>
<TD>sajuks</TD>
<TD>136812</TD>
<TD>2003/01/11</TD>
</TR>
<TR class="evn">
<TD>Roonaan</TD>
<TD>136445</TD>
<TD>2004/08/22</TD>
</TR>
<TR>
<TD>dakyd</TD>
<TD>126449</TD>
<TD>2004/04/11</TD>
</TR>
<TR class="evn">
<TD>knightEknight</TD>
<TD>114794</TD>
<TD>1998/06/24</TD>
</TR>
<TR>
<TD>NETTY4</TD>
<TD>114169</TD>
<TD>2004/12/31</TD>
</TR>
</table>
</center>
</body>
</html>
i want arrows in all 3 columns... and i need some arrows disabled when that column is not sorted...
do u get wht i mean?






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
A give me a second please...
#hof th {padding-right: 10px; background-position: center right; background-repeat: no-repeat;
 background-image:url('https://www.experts-exchange.com/m.gif');}
#hof th.srtasc {background-image:url('https://www.experts-exchange.com/mW.gif');}
#hof th.srtdsc {background-image:url('https://www.experts-exchange.com/mO.gif');}
ur code does not work with my table structure
see my table structure
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<BODY>
<TABLE class=sort-table id=enhancedtable cellSpacing=0 cellPadding=0
   width="100%" border=0>
    <THEAD>
    <TR class=header>
     <TD class=a11BlackBold TF_colKey="name">Name</TD>
     <TD class=a11BlackBold>Descrip
     <TD class=a11BlackBold>One Time Cost</TD>
     <TD class=a11BlackBold>Monthly
     <TD class=a11BlackBold>Mainten
    <TBODY>
    <TR class=dataRow>
     <TD><A
      href="http://169.124.142.145:9080/baiweb/ProductServlet?MethodName=SetProductToAdd&productSeq=1&SucessURL=/baiweb/sdg/ppg/product.jsp?productSeq=1&ErrorURL=/baiweb/sdg/ppg/products.jsp">x236</A></TD>
     <TD class=desc>1 x 3.20 GHz Nocona EM64T processor, 1 MB Cache, 0MB
      (Base memory 2x 512MB removed, 8 Open Memory Slots), Ultra320 SCSI
      Controller, 8x DVD-ROM Std, 2 x 10/100/1000 Ethernet, Hot Swap
      Redundant Power, No Disk Drives (2 Bays). [884121U] (Base memory 2x
      512MB removed, 8 Open Memory Slots), Ultra320 SCSI Controller, 8x
      DVD-ROM Std, 2 x 10/100/1000 Ethernet, Hot Swap Redundant Power, No
      Disk Drives (2 Bays). [883721U]</TD>
     <TD class=a11Black>2,983.00</T
     <TD class=a11Black>N/A</TD>
     <TD class=a11Black>N/A</TD></T
    <TR class=dataRow>
     <TD><A
      href="http://169.124.142.145:9080/baiweb/ProductServlet?MethodName=SetProductToAdd&productSeq=2&SucessURL=/baiweb/sdg/ppg/product.jsp?productSeq=2&ErrorURL=/baiweb/sdg/ppg/products.jsp">IBM
      X346 [8840-PBA]</A></TD>
     <TD class=desc>(1) x346 Rack (2U) ? 1 x Nocona 3.2/800/1MB Cache, 2
      GB RAM, 8x -24x DVD, Hot Swap Redundant Power,RSA2 Slimline
      ServeRAID 7k, 8 Dimm Slots, Dual Channel Ultra320 SCSI Controller, 2
      x 10/100/1000 Ethernet, 1 Hot- Swap Power Supply, No Disk Drives (6
      Bays). [884021U] NOTE: Ensure disk drives are added to this
      configuration. (1) IBM xSeries 3.20GHz/800MHz ? 1MB L2 Cache Nocona
      Processor [13N0663] (1) IBM 2 x 1 GB PC3200 CL2.5 ECC DDR2 RDIMM
      [73P2866] (1) ServeRAID 7k Ultra 320 SCSI Controller [71P8642] (1)
      Remote Supervisor Adaptor II Slimline (No Novell Netware Support)
      [73P9341]</TD>
     <TD class=a11Black>3,091.00</T
     <TD class=a11Black>N/A</TD>
     <TD class=a11Black>N/A</TD></T
    <TR class=dataRow>
     <TD><A
      href="http://169.124.142.145:9080/baiweb/ProductServlet?MethodName=SetProductToAdd&productSeq=3&SucessURL=/baiweb/sdg/ppg/product.jsp?productSeq=3&ErrorURL=/baiweb/sdg/ppg/products.jsp">IBM
      X365 [886261X]</A></TD>
     <TD class=desc>(1) x365 Rack (3U) ? 2 x 3.0GHz Xeon MP, 4MB Cache,
      0MB (Base memory 4 x 512MB (33L3283) removed, 8 Open Memory Slots),
      Ultra320 SCSI Controller, RSA II, CD-ROM removed, 2 x 10/100/1000
      Ethernet, 2 Hot-Swap Power Supplies, No Disk Drives (6 Bays).
      [86626RX] NOTE: Ensure disk drives are added to this configuration.
      (4) IBM 1GB DDR 2100 ECC Memory DIMM (Must be ordered in pairs due
      to interleaving.) [73P2031] (1) ServeRAID 6M Ultra320 SCSI
      Controller [32P0023] (1) IBM 8x SLIMLINE DVD-ROM Drive [22P7047]</TD>
     <TD class=a11Black>10,488.00</
     <TD class=a11Black>N/A</TD>
     <TD class=a11Black>N/A</TD></T
   Â
  Â
            </table>
</BODY>
</HTML>

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
can u pls tell me how do i use ur code in my table
also what shud be done if i do not want sorting in some columns
Therefore I post for any interested the complete code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Zvonko *</TITLE>
<style>
.Report_TableRow0 {
background-color:#E2ECF5;
font-size: x-small
}
.Report_TableRow1 {
background-color:#F0F0F0;
font-size: x-small
}
</style>
<script>
//zpSort.js v1.0.1
var selectedColor = "brown";
var defaultColor = "black";
var sortPar = [];
function initTable(tabName, sortRules){
var theTab = document.getElementById(tabName).getElementsByTagName("tbody")[0];
if(!theTab) return;
theTab.sortPar = {};
theTab.sortPar.hdrRows = 1;
theTab.sortPar.sortCol = -1;
theTab.sortPar.sortDir = false;
theTab.sortPar.datum = [];
theTab.sortPar.numeric = [];
theTab.sortPar.desc = [];
theTab.sortPar.html = [];
theTab.sortPar.dateFormat = [2,1,0];
for(rule in sortRules){
theTab.sortPar[rule] = sortRules[rule];
}
r=theTab.sortPar.hdrRows-1;
var theHead = document.getElementById(tabName).getElementsByTagName("thead")[0];
if(theHead){
theHead.sortPar = {};
theHead.sortPar.hdrRows = theTab.sortPar.hdrRows;
theTab.sortPar.hdrRows=0;
} else {
theHead = theTab;
}
for(var colNum = 0,c=0;c<theHead.rows[r].cells.length;c++, colNum++){
theCell = theHead.rows[r].cells[c];
rTitle = theCell.innerHTML.replace(/<[^>]+>| /g,'');
if(rTitle>""){
theCell.innerHTML += "<span class='sortdir'> </span>";
theCell.title = rTitle;
theCell.onmouseover = function(){setCursor(this, "selected")};
theCell.onmouseout = function(){setCursor(this, "default")};
theCell.onclick = new Function("sortTable(this)");
}
}
theHead.rows[0].cells[0].onclick();
theHead.rows[0].cells[0].onclick();
}
function col(){
var theArray = [];
for(var i=0;i<arguments.length;i++){
theArray[arguments[i]] = true;
}
return theArray;
}
function setCursor(theCell, mode){
rTitle = theCell.innerHTML.replace(/<[^>]+>| |\W/g,'');
if(mode=="selected"){
if(theCell.style.color!=selectedColor)
defaultColor = theCell.style.color;
theCell.style.color = selectedColor;
theCell.style.cursor = "pointer";
window.status = "Click to sort by '"+rTitle+"'";
} else {
theCell.style.color = defaultColor;
theCell.style.cursor = "auto";
window.status = "";
}
}
function sortTable(theCell){
var tBody = theCell.parentNode;
while(tBody.nodeName!="TBODY" && tBody.nodeName!="THEAD" ){
tBody = tBody.parentNode;
}
tHead = tBody;
if(tBody.nodeName=="THEAD"){
tBody = tBody.parentNode.getElementsByTagName("tbody")[0];
}
var colNum = theCell.cellIndex;
var tabOrd = new Array();
if(tBody.sortPar.sortCol==colNum){
tBody.sortPar.sortDir = !tBody.sortPar.sortDir;
} else {
tBody.sortPar.sortDir = tBody.sortPar.desc[colNum];
}
sDir = tBody.sortPar.sortDir;
tBody.sortPar.sortCol=colNum;
arrSpan = "<span class=sortdir> ";
var dateFormat = tBody.sortPar.dateFormat;
if(sDir){
ARROW = "↑";
} else {
ARROW = "↓";
}
oldSort = /<span class="?sortdir"?> [^<]+/i;
for(r=0;r<tHead.sortPar.hdrRows;r++){
theRow = tHead.rows[r];
for(i=0;i<theRow.cells.length;i++){
theRow.cells[i].innerHTML = theRow.cells[i].innerHTML.replace(oldSort, arrSpan+" ");
}
}
theCell.innerHTML=theCell.innerHTML.replace(oldSort, arrSpan+ARROW);
try{
for(i=0,r=tBody.sortPar.hdrRows;r<tBody.rows.length;i++,r++){
numValue = 0;
colCont = tBody.rows[r].cells[colNum].innerHTML.toLowerCase();
if(tBody.sortPar.html[colNum]) colCont = colCont.replace(/<[^>]+>/g,'');
if(tBody.sortPar.numeric[colNum]) {
numValue = parseInt(colCont.replace(/[^\d\-\+\.]*/g,""),10);
if(isNaN(numValue)){
numValue = 0;
if(colCont=='-' || colCont=='n. v.') colCont = "";
} else {
colCont = colCont.replace(/[\d\-\+\.]*/g,"")
}
} else {
if(tBody.sortPar.datum[colNum]){
var datePart = colCont.split(/[\.\-\/]/);
colCont = new Date(datePart[dateFormat[0]],datePart[dateFormat[1]],datePart[dateFormat[2]]);
if(isNaN(colCont)) colCont = new Date(1970,1,1)
}
}
tabOrd[i] = [r, tBody.rows[r], colCont, numValue];
}
} catch(e){
alert(e.message)
}
tabOrd.sort(compRows);
for(i=0,r=tBody.sortPar.hdrRows;r<tBody.rows.length;i++,r++){
tabOrd[i][1].className="Report_TableRow"+(i%2);
tBody.insertBefore(tabOrd[i][1],tBody.rows[r]);
}
window.status = "";
}
function compRows(a, b){
if(sDir){
if(a[2]>b[2]) return -1;
if(a[2]<b[2]) return 1;
} else {
if(a[2]>b[2]) return 1;
if(a[2]<b[2]) return -1;
}
if(a[3] != b[3]){
if(sDir){
if(a[3]>b[3]) return -1;
if(a[3]<b[3]) return 1;
} else {
if(a[3]>b[3]) return 1;
if(a[3]<b[3]) return -1;
}
}
return 0;
}
</script>
</HEAD>
<BODY onLoad="initTable('enhancedtable', {hdrRows:1,html:col(0),numeric:col(2)})" >
<TABLE class=sort-table id=enhancedtable cellSpacing=0 cellPadding=0
width="100%" border=1>
<THEAD>
<TR class=header>
<TD class=a11BlackBold TF_colKey="name">Name</TD>
<TD class=a11BlackBold>Description</TD>
<TD class=a11BlackBold>One Time Cost</TD>
<TD class=a11BlackBold>Monthly Cost</TD>
<TD class=a11BlackBold>Maintenance</TD></TR></THEAD>
<TBODY>
<TR class=dataRow>
<TD><A
href="http://169.124.142.145:9080/baiweb/ProductServlet?MethodName=SetProductToAdd&productSeq=1&SucessURL=/baiweb/sdg/ppg/product.jsp?productSeq=1&ErrorURL=/baiweb/sdg/ppg/products.jsp">x236</A></TD>
<TD class=desc>1 x 3.20 GHz Nocona EM64T processor, 1 MB Cache, 0MB
(Base memory 2x 512MB removed, 8 Open Memory Slots), Ultra320 SCSI
Controller, 8x DVD-ROM Std, 2 x 10/100/1000 Ethernet, Hot Swap
Redundant Power, No Disk Drives (2 Bays). [884121U] (Base memory 2x
512MB removed, 8 Open Memory Slots), Ultra320 SCSI Controller, 8x
DVD-ROM Std, 2 x 10/100/1000 Ethernet, Hot Swap Redundant Power, No
Disk Drives (2 Bays). [883721U]</TD>
<TD class=a11Black>2,983.00</TD>
<TD class=a11Black>N/A</TD>
<TD class=a11Black>N/A</TD></TR>
<TR class=dataRow>
<TD><A
href="http://169.124.142.145:9080/baiweb/ProductServlet?MethodName=SetProductToAdd&productSeq=2&SucessURL=/baiweb/sdg/ppg/product.jsp?productSeq=2&ErrorURL=/baiweb/sdg/ppg/products.jsp">IBM
X346 [8840-PBA]</A></TD>
<TD class=desc>(1) x346 Rack (2U) ? 1 x Nocona 3.2/800/1MB Cache, 2
GB RAM, 8x -24x DVD, Hot Swap Redundant Power,RSA2 Slimline
ServeRAID 7k, 8 Dimm Slots, Dual Channel Ultra320 SCSI Controller, 2
x 10/100/1000 Ethernet, 1 Hot- Swap Power Supply, No Disk Drives (6
Bays). [884021U] NOTE: Ensure disk drives are added to this
configuration. (1) IBM xSeries 3.20GHz/800MHz ? 1MB L2 Cache Nocona
Processor [13N0663] (1) IBM 2 x 1 GB PC3200 CL2.5 ECC DDR2 RDIMM
[73P2866] (1) ServeRAID 7k Ultra 320 SCSI Controller [71P8642] (1)
Remote Supervisor Adaptor II Slimline (No Novell Netware Support)
[73P9341]</TD>
<TD class=a11Black>3,091.00</TD>
<TD class=a11Black>N/A</TD>
<TD class=a11Black>N/A</TD></TR>
<TR class=dataRow>
<TD><A
href="http://169.124.142.145:9080/baiweb/ProductServlet?MethodName=SetProductToAdd&productSeq=3&SucessURL=/baiweb/sdg/ppg/product.jsp?productSeq=3&ErrorURL=/baiweb/sdg/ppg/products.jsp">IBM
X365 [886261X]</A></TD>
<TD class=desc>(1) x365 Rack (3U) ? 2 x 3.0GHz Xeon MP, 4MB Cache,
0MB (Base memory 4 x 512MB (33L3283) removed, 8 Open Memory Slots),
Ultra320 SCSI Controller, RSA II, CD-ROM removed, 2 x 10/100/1000
Ethernet, 2 Hot-Swap Power Supplies, No Disk Drives (6 Bays).
[86626RX] NOTE: Ensure disk drives are added to this configuration.
(4) IBM 1GB DDR 2100 ECC Memory DIMM (Must be ordered in pairs due
to interleaving.) [73P2031] (1) ServeRAID 6M Ultra320 SCSI
Controller [32P0023] (1) IBM 8x SLIMLINE DVD-ROM Drive [22P7047]</TD>
<TD class=a11Black>10,488.00</TD>
<TD class=a11Black>N/A</TD>
<TD class=a11Black>N/A</TD></TR>
</table>
</BODY>
</HTML>
JavaScript
--
Questions
--
Followers
Top Experts
JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.