Multiple selections from drop down list

new BookmarkLockedFalling
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

Post by meerkat on Mar 1, 2018 11:10:29 GMT -5

How do you get multiple selections from a drop down list.
This program works find if you only select one item.
However holding the control key or shift key to select multiple items gives an error...


dim c$(10)
dim d$(10)
for i = 1 to 10
c$(i) = str$(i)
d$(i) = "show-->:";str$(i)
next i

html "<SELECT id='et' name='et' multiple size=5>"
for i = 1 to 10
html "<option value='";c$(i);"'>";d$(i);"</option>"
next i
html "</select>"
print
button #acd, "Search", [r]
print
wait
[r]
a$ = #request get$("et")

print "You Selected:";a$
wait
StefanPendl
Global Moderator
*****

StefanPendl Avatar

Run for BASIC ...
Posts: 945

Post by StefanPendl on Mar 3, 2018 2:54:16 GMT -5

I don't think multiple selections will return a single string, but an array, see stackoverflow.com/questions/11821261/how-to-get-all-selected-values-from-select-multiple-multiple
#request is only able to receive a single string.
At www.w3schools.com/tags/att_select_multiple.asp it is also mentioned that check-boxes should be preferred over multiple selection list-boxes, since they are easier to recognize for multiple selections.
[b]Stefan[/b] - [a href=http://stefanpendl.runbasichosting.com/]Homepage[/a][br][br][b]Please give credit if you use code I post, no need to ask for permission.[/b][br][br]Run BASIC 1.01, Fire-/Waterfox (IE11, Edge), Windows 10 Professional x64, Intel Core i7-4710MQ 2.5GHz, 16GB RAM
meerkat
Senior Member
****

meerkat Avatar

Posts: 250

Post by meerkat on Mar 3, 2018 5:38:13 GMT -5

Thanks Stefan..
I found a way. And I think I actually like it better.
dim c$(20)
dim d$(20)
for i = 1 to 20
c$(i) = str$(i)
d$(i) = "show-->:";str$(i)
next i

html "<table><TR><TD>"
html "<div style='width:220px; height: 200px; overflow: auto'>" '| div to make it scrolled
for i = 1 to 20
html "<input type='checkbox' name='c_";str$(i);"' id='c_";str$(i);"' value='";c$(i);"' >";d$(i);"<BR>"
next i
html "</div>"
html "</TD></TR></TABLE>"

button #acd, "Select", [r]
print
wait

[r]
for i = 1 to 20
a$ = #request get$("c_";str$(i))
if a$ <> "" then print "You Selected:";a$
next i
wait
jerry
Junior Member
**

jerry Avatar

Posts: 86Male

An old guy that cant wait to retire!