Click to See Complete Forum and Search --> : Developing a general STYLE changer in javascript


majik303
08-09-2003, 09:49 AM
Hi, I'm trying to make function in javascript that will change any style I like...given the right parameters. It's pretty simple, but I can't get it to work right.

If I want to change the zIndex of an object, I'd type:
document.getElementById(object).style.zIndex=100

But if I send only parmeters and try to impliment it like this then I have problems:

//code
object = blueBox
styleChanged = zIndex
styleValue = 100

document.getElementById(object).style.styleChanged = styleValue

I KNOW WHERE THE PROBLEM IS.
I can't use the parameter <styleChanged> in the dom code.
I know this because the following works:(notice that I changed <styleChanged> to <zIndex>

document.getElementById(object).style.zIndex = styleValue


This has to be an easy fix.

Can you help?!?!

Exuro
08-09-2003, 11:17 AM
Try using the eval() method:

eval("document.getElementById(object1).style."+styleChanged+"=styleValue")