2〜3の選択ドロップダウンボックスを持つページがあります。私はそれぞれのオプションを同じリストに動的に更新する必要があります。私はそれを更新しようとするたびに、最初のものだけを行います。私は問題がそれを通ってループしていないと思う。複数の選択ボックスを動的に更新する
// HTML
<form id="myForm">
<select id="selectNumber">
<option>Choose a number</option>
</select>
</form>
<form id="myForm">
<select id="selectNumber">
<option>Choose a number</option>
</select>
</form>
<form id="myForm">
<select id="selectNumber">
<option>Choose a number</option>
</select>
</form>
// JavaScriptの
var myArray = new Array("1", "2", "3", "4", "5");
// Get dropdown element from DOM
var dropdown = document.getElementById("selectNumber");
// Loop through the array
for (var i = 0; i < myArray.length; ++i) {
// Append the element to the end of Array list
dropdown[dropdown.length] = new Option(myArray[i], myArray[i]);
}
http://jsfiddle.net/p6eqrxn8/1/
複数の要素に同じIDを付けることはできません。それがIDの全体の理由です。おそらく彼らにクラスを与えることを検討してください。 [相違点を説明するかなり良い記事です。](https://css-tricks.com/the-difference-between-id-and-class/) –
2週間前にこの質問があります。 –