Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19858

Re: How do I get corresponding option field for selected text in html select

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx05.eternal-september.org!.POSTED!not-for-mail
From "Tony" <tony.johansson@inport.com>
Newsgroups comp.lang.javascript
Subject Re: How do I get corresponding option field for selected text in html select
Date Tue, 21 May 2013 10:58:09 +0200
Organization A noiseless patient Spider
Lines 1
Message-ID <knfcng$qs2$1@dont-email.me> (permalink)
References <knf9po$co1$1@dont-email.me>
Mime-Version 1.0
Content-Type text/plain; format=flowed; charset="iso-8859-1"; reply-type=response
Content-Transfer-Encoding 7bit
Injection-Date Tue, 21 May 2013 08:54:09 +0000 (UTC)
Injection-Info mx05.eternal-september.org; posting-host="04290fff4557273ca84c3ad616751e0b"; logging-data="27522"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18HD73Dx/Z7tsJL7nScPGieobBSlkMpDQ0="
X-MimeOLE Produced By Microsoft MimeOLE V15.4.3555.308
In-Reply-To <knf9po$co1$1@dont-email.me>
X-Newsreader Microsoft Windows Live Mail 15.4.3555.308
Importance Normal
Cancel-Lock sha1:CD5adIY8rgiaz6iMbCp3FNZLMSM=
X-Priority 3
X-MSMail-Priority Normal
Xref csiph.com comp.lang.javascript:19858

Show key headers only | View raw



"Tony"  wrote in message news:knf9po$co1$1@dont-email.me...

I have an array called voyageArr where I have the two fields Vesselid and
Vesselname.
I want to add VesselName as display field and Vesselid as the corresponding
field for selected VesselName

Here is the html seelct control
<select id="DDLVesselName">
</select>

Here is how I add data to the html select control. This works fine the
Vesselname is displayed in the html select control.
function Display(flag)
{
       for (var i = 0; i < voyageArr.length; i++)
       {
             $('#DDLVesselName').append($("<option value=" +
voyageArr[i].Vesselid + "></option>").text(voyageArr[i].VesselName));
       }
}


Here is how I get the display field
var ship = $("#DDLVesselName option:selected").text();

How do I write if I want the corresponding option field which is Vesselid
for selected VesselName

//Tony

Here is how I solved my problem.
var select = document.getElementById("DDLVesselName");

           if (select.options.length > 0)
           {
              window.alert("Text: " + 
select.options[select.selectedIndex].text + "\nValue: " + 
select.options[select.selectedIndex].value);
           }
           else
           {
              window.alert("Select box is empty");
           }

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

How do I get corresponding option field for selected text in html select "Tony" <tony.johansson@inport.com> - 2013-05-21 10:08 +0200
  Re: How do I get corresponding option field for selected text in html select "Tony" <tony.johansson@inport.com> - 2013-05-21 10:58 +0200

csiph-web