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
Add a ment  | 

1 Answer 1

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