HTMLフォームFrom Select(複数選択または単一選択)で選択した値を取得

958 ワード

HTMLフォームでのSelect(複数選択または単一選択)の選択値の取得
1.フォーム内のSelectオブジェクトの取得
var a = document.getElementById("   ID");

2.SelectオブジェクトのOptions[]配列を使用できます
var b = a.options;

3.optionオブジェクトのselected属性を用いて選択されたか否かを判断する
if(b[i].selected)

4.ループ判定し、選択されたoptionのvalue値を出力する
for(var i =0;i<b.length;i++)
{
    if(b[i].selected)
    {
        alert(b[i].value);
    }
}