Javascript tip: how to obtain the text of the selected item in a select widget

Javascript tip: how to obtain the text of the selected item in a select widget

  
Say you have a select widget (dropdown), named 'MySelect', that displays these options:

Ferrari
Porsche
Mercedes
BMW

and you want at the browser to get the current model selected by the end-user.

The following javascript shows a message box with that text:
<script>

function f(){
var selObj = document.all.wtMySelect; // Service Studio widgets are prefixed with "wt"
var selectText = selObj.options(selObj.selectedIndex).text;
alert(selectText);

// alert(selObj.value); // this has the selection's underlying value
// alert(selObj.selectedIndex); // this has the index, 0 based
}

</script>