I'm having a little trouble getting the value of a select in my html form. I want a list of dates in a dropdown and when the user clicks on refresh it should do the appropriate action. But when I run in IE7, it comes up with the selectedIndex being undefined.
In my HTML body, I have the select and standard button:
Expand|Select|Wrap|Line Numbers
- <body id="example" onload="displayXML();">
- <div class="divPageHeader" style="width: 100%;">
- <select id="dateSelect">
- <option value="1-Dec-2000">1-Dec-2000</option>
- <option value="1-Dec-2010">1-Dec-2010</option>
- </select>
- <input id="refresh" type="button" value="Refresh" onclick="fnDateChange();" />
- </div>
- </body>
Expand|Select|Wrap|Line Numbers
- <head>
- <script language="javascript" type="text/javascript">
- function fnDateChange()
- {
- var selectedDate = document.getElementById("dateSelect").value
- alert(selectedDate.toString());
- alert("Index = " + selectedDate.selectedIndex);
- var oStartDT = selectedDate.options[selectedDate.selectedIndex].value;
- }
- }
- </script>
Message box alert with 1-Dec-2010
Message box alert with Index = undefined
Script error
Error: 'options' is null or not an object.
Code: 0