/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] way to obtain option text not value?

Hi I am dynamically creating a dropdown list with 2 arrays that I capture from a server query.

[code=html]
<% if (subArray.size() > 1)
{
%>
Sub Boundary:
<select name=”subBoundarySelect” id=”selSubBound” >
<option selected value=”” >

<% for(int j=0; j < subArray.size(); j++)
{
String boundaryName = (String)subArray.get(j);
String boundaryValue = (String)subUrnArray.get(j);
%>
<option value=”<%=boundaryValue%>” id=”<%=boundaryName%>”><%=boundaryName%></option>
<% } %>
</select>
<% } %>

[/code]

boundaryValue is used as a param of a function that opens up a map window. example of boundaryValue swref2397493.

boundaryName is needed for a function to make another query to the server which returns data. example of boundaryName Portland, Seattle, Las Vegas, etc…

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.

Here is a snipet of my javascript function to obtain the text

[code]
a_sub_boundary = document.getElementById(“selSubBound”).id;
[/code]

I have also tried title and name none of these seem to work.

Please let me know if there is a way to obtain the text portion of the option tag. ?

Thanks, Tanya

to post a comment
HTML

3 Comments(s)

Copy linkTweet thisAlerts:
@widdgetzApr 21.2006 — Sure, the key to this is the innerHTML property.

<i>
</i>var sel = document.getElementById("selSubBound");

// of course, change alert to whatever you want to do
alert(sel.options[sel.selectedIndex].innerHTML);


Works cross-browser, I have used it myself a number of times, enjoy!

  • - Ian
  • Copy linkTweet thisAlerts:
    @savageroseauthorApr 21.2006 — Thanks widdgetz!!!

    It works like a charm....
    Copy linkTweet thisAlerts:
    @Mr_JApr 22.2006 — You should also be able to use

    sel.options[sel.selectedIndex].text
    ×

    Success!

    Help @savagerose spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.18,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...