I want this javascript to create options from 12 to 100 in a select with id=\"mainSelect\", because I do not want to create all of the option tags manually. Can you give me
The most concise and intuitive way would be:
var selectElement = document.getElementById('ageselect');
for (var age = 12; age <= 100; age++) {
selectElement.add(new Option(age));
}
Your age:
You can also differentiate the name and the value or add items at the start of the list with additional parameters to the used functions:
HTMLSelectElement.add(item[, before]);
new Option(text, value, defaultSelected, selected);