Reputation: 59
On my HTML page I have a dropdown list containt the numbers 1-5. When the user selects one of these option I want my javascript to grab the option and loop through it however many times selected asking the same group of questions over.
My question is: How do I get the for loop to loop through the selected amount on the dropdown list and output the question that amount of times in the Javascript?
Upvotes: 1
Views: 50
Reputation: 3435
You need to change your last function:
var value = document.getElementById("value").value;
console.log(value);
for (var i = 0; i < value; i++)
{
var output = document.getElementById("test").innerHTML += ("<p>What you want?</p> <select id='animal[i]'> <option value='first'>first</option> <option value='second'>second</option> </select></p>");
}
Upvotes: 2