简体   繁体   English

获取JavaScript中组合框的选定索引的值

[英]get value of selected index of combo box in javascript

i am trying to get the value of the selected index in my javascript 我正在尝试获取我的JavaScript中所选索引的值

here i am defining my list box 在这里,我正在定义我的列表框

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

here i am trying to get the value (inside the form) 在这里,我试图获取价值(在表格内)

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

but its showing "undefined" 但显示“未定义”

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

try this: in your html: 试试这个:在你的HTML:

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

in javascript: 在javascript中:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM