PDA

View Full Version : javascript var problem



Tr4ffic
05-18-2007, 03:15 PM
Hy,

I was wondering if this is correct.
I would like to have a different test every time it does the for(test1,test2,test3..).
This doesn't seem to work.

for(var i=0;i<9;i++){

var test + i = document.creatElement('Button');
}

any help please ????

mwinter
05-18-2007, 03:19 PM
I was wondering if this is correct.
I would like to have a different test every time it does the for(test1,test2,test3..).
This doesn't seem to work.

for(var i=0;i<9;i++){

var test + i = document.creatElement('Button');
}

any help please ????

Whilst it may be possible to perform exactly what you want (it depends on context), consider using an array instead:



var numButtons = 9,
tests = [];

for (var i = 0; i < numButtons; ++i)
tests[i] = document.createElement('button');