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

Instead of building an HTML string, use DOM methods to create and add elements directly:

js
Copy
Edit
function addOptions() {
  const select = document.getElementById('mainSelect');
  for (let i = 12; i <= 100; i++) {
    const option = document.createElement('option');
    option.value = i;
    option.textContent = i;
    select.appendChild(option);
  }
}
addOptions();

This approach avoids innerHTML manipulation and is more robust and secure.