セレクトボックスで選択されているオプション番号を取得する selectedIndex
<form action="" name="sampleform">
<select name="sampleselect" id="">
<option value="">RED</option>
<option value="">BLUE</option>
<option value="" selected>YELLOW</option>
</select>
</form>console.log(document.sampleform.sampleselect.selectedIndex);
document.sampleform.sampleselect.selectedIndex = 0;
console.log(document.sampleform.sampleselect.selectedIndex);selectedIndex
型: 整数型
選択された項目の index を返します。また、このプロパティに index を設定して項目を選択する事もできる
プロパティに -1 を設定すると、項目の選択をすべて解除する。
select要素にmultiple属性が設定した場合は最初のインデックスがかえるので注意。