Skip links

Java Script get combo box selected value

How to get user selected value and text in the drop down box/combo box using java script.Here tested easy best methods to get combo box value.This is describes also browser compatibility.

var comboValue = document.getElementById("ComboID").options[document.getElementById("ComboID").selectedIndex].value;
//This can be write shortly as follows.
  var comboID = document.getElementById("ComboID");
  var comboValue = comboID.options[comboID.selectedIndex].value;
    Index = 0
    Value = 1
    Text  = Red
//******  If you want to get selected text, replace the "text" or "innerHTML" instead of value.

Consider the following example.Note that the brackets.

var comboID = document.getElementById("ComboID");
var comboValue = comboID.options(comboID.selectedIndex).value;

If you are using () instead of [],in Firefox that will give you an ‘is not a function’ error. Because IE allows you to get away with using () instead of [].