Reputation: 59
I want to create several input field with a loop.
idVar[i]= "test"+i;
document.write('<input type="text" id=idVar[i]>');
Instead of different ids, each id is "idVar[i]" instead of "test0","test1",... . So I can't get the input:
myInput=document.getElementById(idVar[i]);
So how can I name the id with a variable?
Upvotes: 0
Views: 1580
Reputation: 85545
Concatenate properly:
document.write('<input type="text" id="'+idVar[i]+'">');
Upvotes: 4