Retrieving the text of the selected <option> in <select> element

Solution 1:

function getSelectedText(elementId) {
    var elt = document.getElementById(elementId);

    if (elt.selectedIndex == -1)
        return null;

    return elt.options[elt.selectedIndex].text;
}

var text = getSelectedText('test');

Solution 2:

If you use jQuery then you can write the following code:

$("#selectId option:selected").html();

Solution 3:

document.getElementById('test').options[document.getElementById('test').selectedIndex].text;