How can I dynamically add options to a select dropdown using JavaScript?

If you prefer building a string and inserting it at once, update your function to generate the full options string, then assign it:

js
Copy
Edit
function selectOptionCreate() {
  let options = "";
  for (let i = 12; i <= 100; i++) {
    options += `<option value="${i}">${i}</option>`;
  }
  document.getElementById('mainSelect').innerHTML = options;
}
selectOptionCreate();

This is simple and works well if you want to replace all existing options.