Click to See Complete Forum and Search --> : getting info from dropdown


pieman
02-03-2003, 06:26 AM
Anyhelp would be greatly appreciated.....

I have a dropdown box - code below.


<select name="report">
<option value="overview">Vacancy overview</option>
<option value="respondent">Respondents</option>
<option value="equalopps">Equal opps</option>
</select>

It's a long story, but what I need to do is (using JavaScript) get the value and the caption of the one they select.

I can get the value using report.value, but is there any way I can get the caption as well? (ie Vacancy overview)

Thankyou!
pieman

gil davis
02-03-2003, 06:39 AM
The preferred, cross-browser method would be:

var sel = document.formName.report;
var idx = sel.selectedIndex;
var opt = sel.options[idx].value; // option value
var cpt = sel.options[idx].text; // caption text

BTW, your example (report.value) is an IE only short cut.

pieman
02-03-2003, 06:46 AM
Fantastic. That works a treat.

Thanks to you both for taking the time to reply.

Much appreciated.
pieman