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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

retrieving Multiple values from my Select list

Status
Not open for further replies.

YvonneTsang

Programmer
Sep 28, 2001
37
CA
I have a Select list that has a bunch of entries. I want the user to select multiple entries and press a button. I have used Selectbox.value but it only seems to give me the first one that is selected. How do I get the rest of the values that have been selected? Is there a way that I can just grab them all appended already? This has been bugging me for a while.

Terry
 
I hope this helps you.
If u want to retrive this options in an ASP page please let me know...

Code:
<HTML>
<BODY>
<select style=&quot;WIDTH: 59px&quot; size=9 multiple name=&quot;select1&quot; id=&quot;select1&quot;>
	<option value=&quot;1&quot; selected>1
	<option value=&quot;2&quot;>2
	<option value=&quot;3&quot;>3
	<option value=&quot;4&quot;>4
	<option value=&quot;5&quot;>5
	<option value=&quot;6&quot;>6
	<option value=&quot;7&quot;>7
	<option value=&quot;8&quot;>8
	<option value=&quot;9&quot;>9
</select>
<br>
<input type=button value=&quot;VBScript Check All&quot; onclick=&quot;doVB();&quot;>
<input type=button value=&quot;JScript Check All&quot; onclick=&quot;doJS();&quot;>
<script language=&quot;vbscript&quot;>
function doVB
	for i=0 to 8 
	  if select1.options(i).selected = true then
		msgbox select1.options(i).value
	  end if
	 next
end function
</script>
<script language=&quot;javascript&quot;>
function doJS()
{
	for(i=0;i<=8;i++)
		if(select1.options(i).selected ==true)
			alert(select1.options(i).value);
}
</script>

</BODY>
</HTML>

________
George, M
 
Hello, shaddow.

I like your demonstration. But I find adding a declaration help me to resolve a little bug. Do you have the same feature in your browser as mine?

function doVB
Dim i
for i=0 to 8
if select1.options(i).selected = true then
msgbox select1.options(i).value
end if
next
end function

regards - tsuji
 
If i let the i variable undeclared is because in vb script u dont need to declare a variable before using unless u are using Option Explicit directive. at least i know that will work in ie3.0 or more... ________
George, M
 
Hello again.

That bit I understand. It's natural. But the &quot;weird&quot; thing is that if you click on the jscript button to verify, then after that, when you try to click on the vbscript button, you, well I, get the runtime error on the variable i. Could you verify it on you box?
No picky, just want to ascertain a feature.

regards - tsuji
 
Thanks for sugestion... It was a litlle mistake, usualy a declare the variable in javascript part, but i've been forgotten.
All i had to do is to declare in javascript part the i cuz that is better then declare it in vbscript.
for(var i=0;i<=8;i++)

Thanks again... tsuji ________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top