-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,674
  • 1
  • 17
  • 30

1 Answers1

7

You can use [] notation:

document.getElementById(destId).style[type] = document.getElementById(sourceId).value;
madox2
  • 45,325
  • 15
  • 94
  • 95