-1

I am trying to create a function that dynamically sets properties based on parameters,

it looks like this

function setPro(sourceId,type,destId){
    document.getElementById(destId).style. + type = document.getElementById(sourceId).value;

}

I'm not sure what to do on setting the type?

is this possible? or am I going to have to do a select case and choose based on that?

Derek
  • 2,927
  • 3
  • 20
  • 33

1 Answers1

7

You can use [] notation:

document.getElementById(destId).style[type] = document.getElementById(sourceId).value;
madox2
  • 49,493
  • 17
  • 99
  • 99