Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop Select for Selected Values

Status
Not open for further replies.

Tim2525

Technical User
Feb 7, 2005
51
0
0
US
Hi All,

Here is my problem. I'm trying to get the value(s) from a select box-multiple which are selected and store them to a variable.

How would I do this? In my loop I'm seeing all items in the select box. I tried using venOption[venIndex].text but it only picked up the first value.

Here is what I have so-far:

Code:
...
var venOption = document.forms[frmName].venID.options;
var venIndex = document.forms[frmName].venID.selectedIndex;

var boxLength = document.forms[frmName].venID.length;
for(i=0; i<boxLength; i++) {
  alert("venSel is ... " + venOption[i].text);
}
...

TIA,
T
 
try this (untested)
Code:
var myForm = document.forms[frmName];
var mySel = myForm.elements['venID'];
var numOpts = mySel.options.length;

for ( var i = 0; i < numOpts; i++ ) {
    if ( mySel.options[i].selected )
        alert(mySel.options[i].value + ' is selected.');
}

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Thanks clFlaVA! I had just figured it out. Appreciate the quick response.

T
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top