admin管理员组文章数量:1399919
Everything I've read online says this is the method and syntax I need to use to get the selected index from a drop down list.
var temp;
temp = document.getElementById("AdvOrBasicSearch_advSearch_ddlState").value;
var sState = temp.options[temp.selectedIndex].text;
However, I get the following error on the last line:
"Microsoft JScript runtime error: 'options' is null or not an object"
Below is a sampling of the drop down list (no need to post all 50 states)
<td><asp:dropdownlist id="ddlState" tabIndex="8" runat="server" EnableViewState="False" Width="150px"
CssClass="clsTextInput">
<asp:ListItem Value=""></asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
<asp:ListItem Value="AK">Alaska</asp:ListItem>
</asp:dropdownlist></td>
Everything I've read online says this is the method and syntax I need to use to get the selected index from a drop down list.
var temp;
temp = document.getElementById("AdvOrBasicSearch_advSearch_ddlState").value;
var sState = temp.options[temp.selectedIndex].text;
However, I get the following error on the last line:
"Microsoft JScript runtime error: 'options' is null or not an object"
Below is a sampling of the drop down list (no need to post all 50 states)
<td><asp:dropdownlist id="ddlState" tabIndex="8" runat="server" EnableViewState="False" Width="150px"
CssClass="clsTextInput">
<asp:ListItem Value=""></asp:ListItem>
<asp:ListItem Value="AL">Alabama</asp:ListItem>
<asp:ListItem Value="AK">Alaska</asp:ListItem>
</asp:dropdownlist></td>
Share
Improve this question
asked Sep 12, 2012 at 21:58
NealRNealR
10.7k61 gold badges167 silver badges306 bronze badges
4
- What does the actual rendered HTML look like? That would be much more useful seeing the script will also interact with that. It would show the actual rendered properties and so on. – Nope Commented Sep 12, 2012 at 21:59
-
1
I'm hoping "everything you've read online" didn't include the
.value
after thegetElementById()
call... :) – Heretic Monkey Commented Sep 12, 2012 at 22:00 -
Where did you get the id
AdvOrBasicSearch_advSearch_ddlState
from? – Hamish Commented Sep 12, 2012 at 22:02 -
2
I can barely read
asp
but this doesn't seem right:temp = document.getElementById("AdvOrBasicSearch_advSearch_ddlState").value
. If I had to take an educated guess, I'd drop the.value
– Jeremy J Starcher Commented Sep 12, 2012 at 22:02
1 Answer
Reset to default 5Thanks to the ments I dropped the .value and everything works fine. Thx guys!
var temp;
temp = document.getElementById("AdvOrBasicSearch_advSearch_ddlState");
sState = temp.options[temp.selectedIndex].text;
本文标签: aspnetGetting selected index from drop down list in javascriptStack Overflow
版权声明:本文标题:asp.net - Getting selected index from drop down list in javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744165275a2593522.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论