[RESOLVED] way to obtain option text not value?

liunx

Guest
Hi I am dynamically creating a dropdown list with 2 arrays that I capture from a server query.<br />
<br />
<br />
<% if (subArray.size() > 1)<br />
{ <br />
%><br />
Sub Boundary: <br />
<select name="subBoundarySelect" id="selSubBound" ><br />
<option selected value="" ><br />
<br />
<% for(int j=0; j < subArray.size(); j++)<br />
{<br />
String boundaryName = (String)subArray.get(j);<br />
String boundaryValue = (String)subUrnArray.get(j);<br />
%><br />
<option value="<%=boundaryValue%>" id="<%=boundaryName%>"><%=boundaryName%></option><br />
<% } %><br />
</select><br />
<% } %><br />
<br />
<br />
<br />
boundaryValue is used as a param of a function that opens up a map window. example of boundaryValue swref2397493.<br />
<br />
boundaryName is needed for a function to make another query to the server which returns data. example of boundaryName Portland, Seattle, Las Vegas, etc... <br />
<br />
I know I cannot use .value to obtain the text portion of the option object and all examples of option objects I have found value and the text are identical. <br />
<br />
Here is a snipet of my javascript function to obtain the text<br />
<br />
<br />
a_sub_boundary = document.getElementById("selSubBound").id;<br />
<br />
<br />
I have also tried title and name none of these seem to work. <br />
<br />
Please let me know if there is a way to obtain the text portion of the option tag. :D <br />
Thanks, Tanya<!--content-->Sure, the key to this is the innerHTML property.<br />
<br />
<br />
var sel = document.getElementById("selSubBound");<br />
<br />
// of course, change alert to whatever you want to do<br />
alert(sel.options[sel.selectedIndex].innerHTML);<br />
<br />
<br />
Works cross-browser, I have used it myself a number of times, enjoy!<br />
<br />
- Ian<!--content-->Thanks widdgetz!!!<br />
<br />
It works like a charm....<!--content-->You should also be able to use<br />
<br />
sel.options[sel.selectedIndex].text<!--content-->
 
Top