tags:

views:

73

answers:

2
+1  Q: 

While doesn't work

function Sort(td)
{
    var t=document.getElementById("theList");
    var rows=t.getElementsByTagName("td");
    var cells=t.cells;
    var bb=true;
    while(bb==true)
    {
    alert(bb);
      for(var i=1;i<rows.length;i++)
       {
           if(cells[td.cellIndex+i*4].innerText<cells[td.cellIndex+(i+1)*4].innerText)
            {

            }
        }
    alert("Works"); //this alert is not reached
    }
}

The second alert will not be shown. Can you tell me why?

A: 

If something goes wrong in any of the code in the for loop it won't reach the second alert. I'd suggest running this in a JS debugger.

Cogwheel - Matthew Orlando
+2  A: 

Your var rows is an array, which will not have a property "cells". That could be your problem right there.

Robusto
+1. Also wondering if it should be `var rows=t.getElementsByTagName("tr");` rather than `td`
Martin Smith
@Martin Smith: hmm... that sounds suspiciously like it makes too much sense.
Andy E
@Martin: Probably right. I sense what he is trying to do, but I just wouldn't do this the same way. I'd probably use nested for loops instead of a while. I almost *never* use a while loop, if I can help it.
Robusto