Get selection box current text and value.

Hello all,back with another noob question,

Is there any way to get hold of the current text and value attributes for a selection box? (not a combo box).

I have a selection box within a form called transportForm list called addTransportSel and i need to get hold of the text and value currently set and store them variables ive tried;

transportForm.getItemValue(“addTransportSel”);
transportForm.getItemText(“addTransportSel”);
And
addTransportSel.value
addTransportSel.text

but neither works as they both return null, probably some very simple way of doing it can anyone point me in the right direction?

Thanks in advance.

Hi

transportForm.getItemValue(“addTransportSel”); should give you value of selected option
transportForm.getItemText(“addTransportSel”); should return you text label next to select

also you can:
var opts = transportForm.getOptions(“addTransportSel”); will return you options array - you can extract option text

Hi all,

Thanks Andrei, your suggestion put me on the right track for other noobs (like me :wink: ) out there this is how I did it:

var opts = yourFormName.getOptions("yourSelBoxName");
// get the currently selected option and then its text attribute. 
var text = (opts[opts.selectedIndex].text);

Captain_Ludd, thank you for sharing! :slight_smile: