Is there a way to populate two dropdown menus in JavaScript with numbers using the same for loop? Currently, only one is being populated, specifically the last one.
for (var i=1; i<10; i++)
{
var option = document.createElement("option");
option.text = i;
option.value = i;
document.getElementById('first').options.add(option);
document.getElementById('second').options.add(option);
}
It seems that 'second' gets populated while 'first' does not. If I switch the order of 'second' and 'first', then 'first' gets populated instead.
Is there a way to achieve this without having to use two separate for loops? I have tried passing the ID via a function but still end up with the same result.
Any suggestions would be greatly appreciated. Thank you.