View Full Version : Resolved Converting variable to argument?

09-27-2008, 06:36 PM

I hope I've got my terminology correct here but if not please bare with me.

Is it possible without using a huge switch statement to do something like the following:

Pass the element id, required style type and style definition to the function

<div id="test">
<a href="javascript:fAddStyle('test', 'color', 'red');">Click here</a>

And then somehow covert the variable "color" to the JavaScript argument .color

function fAddStyle(sElementId, sStyle, sAttribute) {
// Missing conversion of variable //
document.getElementById(sElementId).style.sStyle = sAttribute;

i.e I can use one small function to convert any style to any attribute and not have a big switch statement covering off every possible .style type that may come up.

Any pointers to what I should read to improve my terminology in this area would be appreciated too :)

09-27-2008, 06:52 PM

09-27-2008, 06:55 PM
aah you beauty :thumbsup: Nice and simple.

I always seem to have a bit of trouble with my []s and using them correctly.