Demo: Add Options to a Select from an Array

The month list below starts with one placeholder. JavaScript adds all twelve months after the DOM is ready.

The original demo made its source available to users. The complete JavaScript and HTML used here remain available below.

JavaScript Used in This Demo Top ↑

const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const monthList = document.getElementById("monthList");
months.forEach((month) => {
  monthList.add(new Option(month, month));
});

HTML Used in This Demo Top ↑

<form action="yourpage.php" method="post">
  <label for="monthList">Month</label>
  <select id="monthList" name="Month_list">
    <option value="">Month list</option>
  </select>
</form>

Adding options tutorial · Listbox · Select the current month by default




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer