i cant get combobox value in IE.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirmalsingh
    New Member
    • Sep 2006
    • 218

    i cant get combobox value in IE.

    hi all,
    [HTML]
    <select name="cmbDepart ment" id="cmbDepartme nt" style="width:12 0px">
    <option >winding</option>
    <option>Testing </option>
    </select>
    [/HTML]
    javascript
    Code:
    var strDepta=document.getElementById('cmbDepartment');
    var strDept=strDepta.options[strDepta.selectedIndex].value;
    alert(strDept);
    An empty alert is displayed in IE, but works fine in FF. what will be the problem? thanx in advance.
  • mrhoo
    Contributor
    • Jun 2006
    • 428

    #2
    <select name="cmbDepart ment" id="cmbDepartme nt" style="width:12 0px">
    <option >winding</option>
    <option>Testing </option>
    </select>
    var strDepta=docume nt.getElementBy Id('cmbDepartme nt');
    var strDept=strDept a.options[strDepta.select edIndex].value;
    Firefox will return the text if there is no value, but that's browser dependent, and only seems to apply to options.

    if you want the text of an option you should be explicit, for IE and others-

    var strDept=strDept a.options[strDepta.select edIndex].text

    If you want anything uploaded to a server, be sure to set value attributes on your options-
    <option value="0" selected= "selected">Sele ct</option>
    <option value="1">windi ng</option>
    <option value="2">Testi ng</option>

    Then you can find the value of an option in any browser with .value.

    Comment

    Working...