Search code examples
javascriptgridviewdrop-down-menuselectedvalue

How do you get a selected value from gridview dropdown using javascript


i have a gridview which has one of the columns as a dropdown. When the user selects a different drop down option i would like to get the selected value. How do i go about this? Please see code below. This code seems to work in IE9 and Firefox but does not work in IE8. In IE8 i get the following error "options.selectedIndex' is null or not an object" .

     var gridview =  document.getElementById('ctl00_ContentPlaceHolder1_grvTrainHistoryCapture');

     if (selectedRowIndex == null) return;
     var statusCell = gridview.rows[parseInt(selectedRowIndex)+ 1].cells[5];
     var ddlStatus = statusCell.childNodes[1];

     var statusID = ddlStatus.options[ddlStatus.options.selectedIndex].value;

Solution

  • EDIT: I HAVE TESTED THIS CODE UNDER IE8, AND IT WORKS AS IT SHOULD. i guess the problem is the object you are passing.

    <script type="text/javascript">     
        var e = document.getElementById('test');
        alert(e.options[e.selectedIndex].value );
    </script>