...

View Full Version : Using a variable as a object name in a statement



sslrgrt
02-23-2003, 11:32 PM
I'm trying to change the class of a table cell using JavaScript with the onClick event of another cell.

If I use the cell ID (tab1) in the statment:

tab1.className="tabmenuoff";

it works.

But if I assign the cell ID value to a variable and use that as the object ID in the statement:

var tabname="tab1";
tabname.className="tabmenuoff";

it doesn't. But I get no errors

I need to use a variable because I need to change a number of cells and use the 'for' loop to accomplish this using the numeric value on the end of the object name.

I'm sure the answer is very simple but I'm new to this - can anyone help!!!!

rsci
02-24-2003, 12:56 AM
The statement:

tabname.className="tabmenuoff";

Still has the script looking for a cell named "tabname". Some one will need to jump in here but you would do something like the following:

cells[tabname].className="tabmenuoff";



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum