Hi Bodie,
I have been trying your suggestion, but no luck so far..
Here is what I have been trying:
(I have a bunch of forms on this page and 'adjIndex' is the index of the row that I am trying to edit and 'AdjustmentsTable' is the Id of the table whose rows I am trying to edit)
for(var j=0; j<document.forms.length; j++)
{
for(var i=0; i<document.forms[i].elements.length; i++)
{
var elementX = document.forms[j].elements[i];
if(elementX.id =="AdjustmentsTable")
{
for(var k=0; k<elementX.rows.length; k++)
{
if(elementX.rows[k].rowIndex == adjIndex)
elementX.rows[k].background = "#00FF00";
}
}
}
}
Can you take a look and point out if I am making in mistake. I am getting that error that 'elementX.id is not a object or is equal to null'.
Thank you in advance,
Chuck
Originally posted by Bodie Minster:
[B]If you are developing for IE 5.0 or above or Netscape 6 or above, then you can use the table object model and it's a sinch. If you are developing for older browsers, then you have to use the document object model and it's a little bit trickier, but still not too bad.
In the table object model you would give your table an ID and then you could traverse it like so:
To keep track of the current row you would not need the inner loop, but I just wanted to illustrate the table object model. You could use the row's rowIndex property in a variable to keep track of which row is selected. Then you could use style.background to "highlight" the row. If you are using any style sheets in your cells or other children, then you will have to set the background at the cell level instead of the row level. You could do this with the DOM like so:
Depending on the structure of your table, you may need to change your approach a little, but the basic idea should work for you. However you navigate the table, onClick in any of the table's children should:
1) Reset the background of the currently selected row.
2) Find the enclosing table row of the element that was clicked
3) Reset the variable that stores the current row to point to the new row.
4) Set the new row's background color to indicate the selection.
HTH
[/B]