admin管理员组文章数量:1328601
I have an ASP.NET website, with the following code in an .aspx
page.
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
When this renders in HTML, I get the following
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
And on my HTML page, I see this
When I use this javascript to return the selectedValue
of the option, I get the value undefined
returning. Can someone please tell me what I'm doing wrong???
var e = document.getElementById("SelectEquipmentDropdown");
var selectedEquipmentDropdown = e.options[e.selectedIndex].Value;
I have an ASP.NET website, with the following code in an .aspx
page.
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
When this renders in HTML, I get the following
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
And on my HTML page, I see this
When I use this javascript to return the selectedValue
of the option, I get the value undefined
returning. Can someone please tell me what I'm doing wrong???
var e = document.getElementById("SelectEquipmentDropdown");
var selectedEquipmentDropdown = e.options[e.selectedIndex].Value;
Share
Improve this question
asked Jun 27, 2016 at 21:17
Brendan GoodenBrendan Gooden
1,5613 gold badges26 silver badges48 bronze badges
1
-
Try
e.value
instead. – Alex Kudryashev Commented Jun 27, 2016 at 21:23
1 Answer
Reset to default 5.Value
should be.value
see fiddle https://jsfiddle/Lddyn573/9/
<form action="#" id="demoForm" class="demoForm">
<select id="SelectEquipmentDropdown" onchange="myFunction()">
<option value="1">1</option>
<option value="2">2</option>
</select>
</form>
<script>
function myFunction(){
var e = document.getElementById("SelectEquipmentDropdown");
var selectedEquipmentDropdown = e.options[e.selectedIndex].value;//change it here
alert(selectedEquipmentDropdown);
}
</script>
本文标签: jqueryJavascript get Selected Value returning 39undefined39Stack Overflow
版权声明:本文标题:jquery - Javascript get Selected Value returning 'undefined' - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742225334a2436207.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论