在JavaScript中出现Sel位置错误 [英] Getting Error in Sel position in javascript
本文介绍了在JavaScript中出现Sel位置错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在javascript中遇到错误,因为"Microsoft JScript运行时错误:"options"为null或不是对象"
"
Hi,
I am getting error in javascript as "Microsoft JScript runtime error: ''options'' is null or not an object "
var sel = document.forms[0].elements("Emp").value;
alert(sel);
var pos = sel.selectedIndex; //'Displaying "undefined
alert(pos);
var optText = sel.options[pos].text; //"Error in 'options' is null or not an object "
有什么问题...?
附加:
what is the problem...?
ADDITION:
function ViewAllted() {
if(document.forms[0].Emp.value!=''){
//var sel = document.getElementById("Emp");
var sel = document.forms[0].elements("Emp").value;
alert(sel);
var strValue = sel.options[sel.selectedIndex].value;
alert('Sselected Value is: ' + strValue + ' and Index is: ' + sel.selectedIndex);
var optText = sel.options[strValue ].text;
document.forms[0].EmpName.value = optText;
}
document.forms[0].action="FORMEMP.aspx?M=V" document.forms[0].submit();
} else {
alert("Select an Employee!")
}
}
<input type="button" onclick="Javascript: ViewAlloted()" value="View Existing Allocation" />
推荐答案
嗨 使用以下代码获取所选索引
Hi Use following code to Get Selected Index
var sel = document.getElementById("Emp");
var strValue = sel.options[sel.selectedIndex].value;
alert('Selected Value is: ' + strValue +' and Index is: ' + sel.selectedIndex);
谢谢,
Imdadhusen
Thanks,
Imdadhusen
这篇关于在JavaScript中出现Sel位置错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文