user2867054
user2867054

Reputation: 59

Javascript variable input id

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

Answers (1)

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

Concatenate properly:

document.write('<input type="text" id="'+idVar[i]+'">');

Upvotes: 4

Related Questions