0

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?

1
  • 1
    document.write('<input type="text" id="'+idVar[i]+'">'); Commented Jul 18, 2014 at 14:38

1 Answer 1

4

Concatenate properly:

document.write('<input type="text" id="'+idVar[i]+'">');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.