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!

Selecting Multiple values in list box 1

Status
Not open for further replies.

pkailas

Programmer
Jun 10, 2002
555
0
0
US
I'm trying to set multiple rows or values to selected based upon a query. It seems to set the "selected" but only the last value selected actually displays as selected. Anyone know what I am doing wrong?

In the first part I take what is in the database, which is using the | to separate the values and put it into an array.
Code:
	'put all selected equipment types in an array
	dim arEquipmentSelected
	arEquipmentSelected = split(rs("LEquipment"), "|")

Then as I'm populating the list box I check to see if any of the values match what is in the array. If so I set the strSelected variable and build the string.
Code:
	do while not rsEquip.EOF
		if strEQID = trim(rsEquip("EQID")) then 
			strSelected = " selected" 
		else 
			for item = 0 to ubound(arEquipmentSelected)
				if arEquipmentSelected(item) = trim(rsEquip("EQDesc")) then				
					strSelected = " selected" 					
				else
					strSelected = ""
				end if
			next 
		end if
		
		StrEquipList = StrEquipList & "<option value=" & chr(34) & trim(rsEquip("EQDesc")) & chr(34) & strSelected & ">" & trim(rsEquip("EQDesc")) & "</option><br>"
		rsEquip.MoveNext
	loop
	rsEquip.Close

And then to actually load the list box in html the following:

Code:
<td>Equipment: for multiple press CTRL Key<br><select name=equip multiple style="width:300;height:70;"><%=StrEquipList%></select></td>

_______
I love small animals, especially with a good brown gravy....
 
I think StrEquipList is inside the do loop and will get rewritten each time you go through the loop?

Maybe after you set selected or not selected based on whether it hits the recordset you should store it back to the array and then loop through the array to write your list box? I don't know.

 
[tt] if strEQID = trim(rsEquip("EQID")) then
strSelected = " selected"
else
[blue]strSelected = ""[/blue]
for item = 0 to ubound(arEquipmentSelected)
if arEquipmentSelected(item) = trim(rsEquip("EQDesc")) then
strSelected = " selected"
[red]exit for[/red]
[red]'[/red]else
[red]'[/red] strSelected = ""
end if
next
end if
[/tt]
 
tsuji,

Thank you for catching what I should have seen! Sometimes I can't see the forest for the trees.

_______
I love small animals, especially with a good brown gravy....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top