0

I am trying to use the following for loop but still showing one option.

var x = document.getElementById("cars");
var option = document.createElement("option");
for(var i=0;i<5;i++)
{
    option.text = "BMW";
    x.add(option);
}
1
  • try to move createElement inside loop Commented Nov 18, 2019 at 9:20

1 Answer 1

1

You could initiate createElement variable inside the loop

var x = document.getElementById("cars");
for(var i=0;i<5;i++)
{
    var option = document.createElement("option");
    option.text = "BMW";
    x.add(option);
}
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.