stormdrain
stormdrain

Reputation: 7895

Set element style/property in for loop

I'm trying to set properties of some elements through a for loop, but am confused about the implementation.

Here is the code:

var fiArray = new Array('name','address','address2','phone','fax','misc1','misc2');

function disableFields(){
   for(i=0,x=fiArray.length; i < x; i++){
       var disEl = "$('formID')."+fiArray[i];
       disEl.disabled=true;
   }

}

I've tried every permutation of changing the disEl var, not using a var, concatenating different parts of the disEl string; nothing seems to work.

I know I'm missing something simple and fundamental here...

p.s. using prototype

Upvotes: 0

Views: 350

Answers (1)

Amarghosh
Amarghosh

Reputation: 59451

var disEl = $('formID')[fiArray[i]];

Upvotes: 2

Related Questions