获取javascript中组合框所选索引的值

get value of selected index of combo box in javascript

本文关键字:索引 javascript 组合 获取      更新时间:2023-09-26

我试图在我的javascript中获得所选索引的值

这里我定义了列表框

<select name="combo" id="combo"  OnBlur="retrieveData(this.form)" ></select>

这里我试图获得值(在表单内)

    alert(form.combo.value); // NOT working
    alert(form.combo.selectedIndex)  // working
    alert(form.combo.selectedIndex.value)  // NOT working

但是显示"undefined"

form.combo.options[form.combo.selectedIndex].value;

试试这个:在你的html中:

<select name="combo" id="combo" OnBlur="getComboVal(this)" ></select>
在javascript:

function getComboVal(sel)
{
    alert (sel.options[sel.selectedIndex].value);
}