Javascript get dropdown box selected value
How to get user selected value and text in the drop-down 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;
/*
Output
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 [].
What's your reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0





