f



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

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


0
5/21/2013 8:08:10 AM
comp.lang.javascript 38370 articles. 2 followers. javascript4 (1315) is leader. Post Follow

1 Replies
557 Views

Similar Articles

[PageSpeed] 30


"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");
           }

0
5/21/2013 8:58:09 AM
Reply:

Similar Artilces:

trying to disable a text input field when a particular select list option is selected in a select field but this code has no effect
<script> $(document).ready(function () { $('#select_field').change(function(e) { if (e.target.value=='select_value') {e.second_field.disabled = true;} }) }) </script> On 2015-11-30 05:23, fugee279@gmail.com wrote: > <script> > $(document).ready(function () { > $('#select_field').change(function(e) > { > if (e.target.value=='select_value') {e.second_field.disabled = true;} > }) > }) > </script> Next time, please include the error message you see in the console. The para...

get the selected OPTION from SELECT
In the code below I want to alert the selected option of select. In Mozilla the code works (If I choose "3" alerts it). In IE alerts: nothing appear --------------------- <script> function hi() { d = document.getElementById("day").value; alert(d); } </script> <select id=day onchange="hi();"> <option>0 <option>1 <option>2 <option>3 <option>4 </select> --------------------- On 11/03/2006 19:31, Chameleon wrote: [Getting selected option element] Read the group FAQ: <http://www.jibbering.com/faq/> ...

HTML select field where the OPTION text is of different colors
Hi Is it possible to have an HTML select field where the OPTION text is of different colors? <select> <option>Black_text (yellow_text)</option> </select> I tried using an CSS SPAN element to color the text but that doesn't seem to work. Any ideas? "venky_lb" <lb.venky@gmail.com> wrote in message news:126b4778-ace0-4a04-8a8c-0d2ec2793234@k10g2000prh.googlegroups.com... > Hi > > Is it possible to have an HTML select field where the OPTION text is > of different colors? > > <select> > <option&...

Pass variable selected from drop down option field to text fields
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post" action="results.asp"> <select name="region" size="10"> <option value="Choice 1" JavaScript "SET Text Box 1 to 12:00; SET Text Box 2 to 5:00">Choice 1</option> <option value="Choice 2...

HTML Select option selected color style
Is there a style for a select option's "selected" color? For example: <HTML> <BODY> <FORM NAME="form1"> <SELECT NAME="mySelect" SIZE="7" style="background-color:red;"> <OPTION>Test 1 <OPTION>Test 2 <OPTION>Test 3 <OPTION>Test 4 <OPTION>Test 5 <OPTION>Test 6 <OPTION>Test 7 </SELECT> </FORM> </BODY> </HTML> When I select an option it turns blue, I want to override this and make it a different color. In the style I expected something ...

selecting an option from a select
Hi! Since the first questions I asked here, I continue to drop by and read some topics here and there, I like the replies very much. I have today another question, I don't seem to find it on the FAQ (please point me if its there): I have two selects, one written 'directly on the page' and a second written dinamically by JavaScript. (Actually, both are written by php using data from a DB). One is dependable of the other, and I am using the code of DevArticles to make them depend: http://tinyurl.com/df6vf The Question: Now, I want to select the selected option of both inputs, af...

programmatically select an option in "select" box in html
Hi, I'm having trouble selecting an option in html, i.e. i change the code, but the change is not reflected in the browser. Example, i have <select> <option>A <option selected>B </selected> if I click A and refresh the page, the select box will still be in A, even though according to the code should be pointed to B. I'm using firefox. Any suggestion? thanks rvelosoo wrote: > I'm having trouble selecting an option in html, i.e. i change the > code, but the change is not reflected in the browser. > Example, i have > <select> > <opti...

Select from (select)
This is a multi-part message in MIME format. ------_=_NextPart_001_01C43384.9C3B5D61 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Is it possible to do a select from a select statement in Informix? Ex: Select Customer from (Select Customer, sum(invoiced_amt) as total_spent from Customers group by Customer) where total_spent > 1000 ------_=_NextPart_001_01C43384.9C3B5D61 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; = charset=3Dus-ascii"> <META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version = 6.5.6944.0"> <TITLE>Select from (select)</TITLE> </HEAD> <BODY> <!-- Converted from text/rtf format --> <P><FONT SIZE=3D2 FACE=3D"Arial">Is it possible to do a select from a = select statement in Informix?</FONT> </P> <P><FONT SIZE=3D2 FACE=3D"Arial">Ex:</FONT> <BR><FONT SIZE=3D2 FACE=3D"Arial">Select Customer from (Select Customer, = sum(invoiced_amt) as total_spent from Customers group by Customer) where = total_spent &gt; 1000</FONT></P> </BODY> </HTML> ------_=_NextPart_001_01C43...

Get selected text from JEditorpane as HTML
Is it possible to get the selected text as HTML from the pane? the getSelectedText seems unable to do this. This is required for a customized copy & paste action. The implemented copy function interprets the </P></P> as a new line (/n), while <BR> tags are replaced by a space. Also, pasting text copied from the JEditorpane is inserted as "</P>"+clipboardcontent+"<P>". According to current html standards, <BR> tags are considered wrong. It should be <BR/>. Anyway to make this clear to the JEditorpane? Gerrit Hulleman wrote: ...

How to select all texts of the document of the format of the selected text?
Hi,i have selected a text of the document with the specified font face, color and size in MS Word 2000. Now , I want to select all the relevant texts from the entire document with the same format(face,color and size) as of the selected text. so Is there any method or shortcut to do this op.? Not really. You have to "walk" the document checking the styles as you go along. And You have to watch out for cases where the style changes in the middle of a word (!) and code accordingly to get the desired results. chetan26nov@gmail.com wrote: > Hi,i have selected a text of the documen...

Getting the selected text in Acrobat Javascript?
Hello, I would like to be able to get the selected text in a PDF document from within Acrobat Javascript (as simple text). Is this possible? If so, how? The Span object apparently supports only text in form text fields. Thanks in advance. ...

select.select()
please help me.. what does the following line do? read_sockets,write_sockets,error_sockets = select.select(CONNECTION_LIST,[],[]) In article <b8d42424-e0ab-4595-9c87-25e5c1b53349@googlegroups.com>, Bhanu Karthik <bhanukarthik2002@gmail.com> wrote: > please help me.. what does the following line do? > > read_sockets,write_sockets,error_sockets = > select.select(CONNECTION_LIST,[],[]) This is a little tricky. First,read the docs at http://docs.python.org/2/library/select.html. There's a lot of complicated stuff there, but just concentrate on the description of the select.select() call for now. Imagine a process which has a lot of network connections open. A great example would be something like a MUD (Multi User Dungeon). You've got one server process(*) and a bunch of clients which have all made TCP connections over individual sockets. Each client will be sending commands asynchronously, and the server needs to handle this. You need some way to figure out which of those sockets have something that's been sent to you (which you need to process) and which are just sitting idle. That's where select() comes in. It gives you a way to say, "Here's a list of sockets. Sleep until one of them has something available for me to read, and let me know which one." One bit of complication is that you can also check for sockets which are ready to be written on, and sockets which ...

Getting HTML from a users text selection
Hi guys, Using the following function function class_getSelection(){ if (browser.isIE5up) { return EpozElement.contentWindow.document.selection; } else { return EpozElement.contentWindow.window.getSelection(); }; } I can get the text that a user has selected on a page. However it parses out all the html and just returns the selection as plain text. Is there any way to return the users selection including any HTML tags. ...

Select Option & selected
Hello all, I'm currently writing a tiny little bit of navigation to a page, and I've come across this stumbling block: Goto Page&nbsp;&nbsp; <select name="page"> <SCRIPT LANGUAGE="JavaScript1.2" > for ( var inc = 1; inc <= <%=nPages%>; inc++ ){ document.PageForm.page[inc-1] = new Option(inc, inc, ((inc == <%=nPage%>) ? true : false)); } </SCRIPT> </select> On firefox, the select box generated behaves exactly as expected, producing a select with all the 'pages' available, and the currently selected page as...

select: how to detect same option selected?
onChange() is working very well, when an option is choosen the first time. how can i detect when the user clicks and choose the same option again? this code works with IE 6.x. you can click the same option again and again and the onChange()-event comes up. firefox will react on the onmousedown but the onChange is not executed. is there a way to detect selecting the same option again and again? <html> <head> <script> function selChange (feld) { alert (feld.options[feld.selectedIndex].value); } </script> </head> <body> <FORM> <SELECT onmo...

options.selected on select multiple
Hi ! I have a problem with Internet Explorer that I really can't explain. If anyone can find a solution to this, I congratulate you... I'm trying to have a script dynamically select all (or some) of the options in a select field. It won't work, it will only select one option at a time... While I was trying to debug, I realized that if I put an alert before the instructions, it will work !!! I've been able to recreate the problem in a simple html file... try this ! First run the file as it is here... one option is selected. Then, uncomment the alert("test"); lin...

Select element with no selected options
Hello All, Is it possible to create a <select> element with no selected options? I have tried setting the selectedIndex attribute to -1, but as far as I can tell this only works for <select multiple> elements. Am I missing something obvious? Sincerely, TJ Walls Ph.D. Candidate - Stony Brook University On Wed, 27 Oct 2004 07:47:47 -0400, TJ Walls <tjwalls@mindspring.nospam.com> wrote: > Is it possible to create a <select> element with no selected options? By not giving any OPTION elements the selected attribute, it is possible for a user agent to initial...

Javascript for HTML select/option form with lots of entries
I have an HTML select/option form with about 400 entries (10-digit customs codes) and it's a bit tiring to scroll up and down to find the right customs code. I was wondering if there is some Javascript which would facilitate the selection of the right entry. For instance initially all 400 entries are displayed as selectable options. Then you type a "3" and all entries starting with 3 are displayed as a scrollable list from which you can choose one entry. Then suppose you type a "7" and all entries starting with "37" are displayed. You can...

wxSTC: New text selection not possible within selected text
A rather annoying effect, when I want to start a new text selection within an already selected text nothing happens. I first have to deselect the text (by clicking outside of the selected text) and then can set a new overlapping selection. SciTe doesn't have this problem so it must be either in wxSTC or wxWindows. O. Wyss -- See "http://wxguide.sourceforge.net/" for ideas how to design your app. otto.wyss@bluewin.ch: > A rather annoying effect, when I want to start a new text selection > within an already selected text nothing happens. I first have to >...

select (select ...)/(select ...) ... -> 0 !!
Hi I need to do a query like this one : Select *, (select count(*) from request where allowed='t' and lead_id=lead.id and lead.affiliate_id=affiliate.id) as nb_bogus_leads, (select count(*) from lead where affiliate_id=affiliate.id) as nb_leads_submitted, (select count(*) from request where allowed='t' and lead_id=lead.id and lead.affiliate_id=affiliate.id)/(select count(*) from lead where affiliate_id=affiliate.id)*100 as percentage_bogus_leads from affiliate where website='dev' but in this one, the part : (select count(*) from request where allowed='t' and lead_id=lead.id and lead.affiliate_id=affiliate.id)/(select count(*) from lead where affiliate_id=affiliate.id)*100 never works and always give me 0 as a result ... Is it possible that postgresql doesn't support expessions like select (select ...)/(select ...) ... ?! Thanks for your help Krystoffff ...

How to get selected text from a text edit control?
I created a text edit control using CreateEditTextControl. I can get the current text by calling char buf[256]; Size textSize = 0; GetControlData(controlRef, kControlEditTextPart, kControlEditTextTextTag, 255, buf, &textSize); but how do I get only the text that is currently selected (highlighted)? thanks, Shai In article <1111086224.345185.78280@g14g2000cwa.googlegroups.com>, shai@waves.com wrote: > I created a text edit control using CreateEditTextControl. > I can get the current text by calling > > char buf[256]; > Size textSize = 0; ...

update text field based on selection field
ok, this is gonna seem stupid, but it has been stumping me all afternoon. I have two fields on a HTML page. HTML looks like this... <html> <head> <title>New Page 3</title> </head> <body> <form method="POST" action="index.asp"> <select size="1" name="shiptype" onchange="crazyJavascriptFuntion()"> <option selected>SELECT ONE</option> <option value="3">GROUND (3 DAY)</option> <option value="2">2ND DAY AIR (2 DAY)</option> <option value=&qu...

Select and get text from Edit text filed
Hi, I need to make a simple text editor in matlab gui. I want is the user to be able to select part of the text he had typed and make the fontweight bold. I don't know how to get the selected text. Can you give me some clues? Thanks. ...

Getting selected values from a select statement
Hi, I have the following code in the HTML <select size="1" name="newtitle"> <% // Need to fill select with available campuses while (titleit.hasNext()) { temp = (String)titleit.next(); // Check if it is the selected campus already if (temp.equals(title)) { // Make it the selected campus by default out.println("<option selected>"+temp+"</option>"); } else { // Add it normally out.println("<option>"+temp+"</option>")...

Web resources about - How do I get corresponding option field for selected text in html select - comp.lang.javascript

Rubio's Survival Is on the Line in Tonight's Debate
HIALEAH, Fla. — Marco Rubio’s homecoming to Florida will likely be far from the triumphant one many Republicans once expected and that his campaign ...

Top Google exec travels the world in inspiring search for work/life balance
Even at the edge of the world, Patrick Pichette couldn't quite escape Google. Earlier this year, Pichette and his wife were preparing to leave ...

PlayStation VR boss was surprised by Oculus Rift’s $599 price
Virtual reality is new and hot, and it turns out that new hot things cost a lot of money — unless they’re made by Sony? That’s one possible interpretation ...

George R.R. Martin Is Not Dead: ‘Game Of Thrones’ Novelist Mistaken For Beatles Producer After News Of ...
Yesterday, the music industry was devastated after news of George Martin’s passing spread online. George Martin, a record producer known as the ...

Search on for suspects in Pa. shooting that left 5 dead
WILKINSBURG, Pa. (AP) — Police were searching early Thursday for at least two gunmen who opened fire during a backyard party in suburban Pittsburgh, ...

Germany says it has obtained files on Islamic State members
BERLIN (AP) — Germany's federal criminal police said Thursday they are in possession of files containing personal data on members of the extremist ...

Apple's Eddy Cue on FBI iPhone feud: 'Where does it stop?'
Apple continues to make its case in the court of public opinion about its ongoing dispute with the FBI. In a Spanish interview with Univision, ...

Beyonce ‘Respects Kim Kardashian For Nude Photo Scandal,’ Similar To ‘Formation’ Black Panther Backlash ...
Beyonce is reportedly applauding Kim Kardashian’s recent publicity stunt, which saw the reality star unveil two naked photographs of herself, ...

Dr. Luke’s Lawyers Deny Rumors Sony Will Drop Him Amid Legal Battle With Kesha
Dr. Luke has denied reports suggesting that Sony is about to drop him amid his legal battle with pop singer Kesha, ABC News reports. Dr. Luke ...

Watch A Video Of A Self-Driving Google Car Slamming Into A Bus
A new video showing Google’s self-driving car crashing into a bus in Mountain View, California has been uploaded on the internet. The Associated ...

Resources last updated: 3/10/2016 1:11:03 PM