Select multiple items from a dropdown

J

Jas

I want an ASP page with a dropdown and a simple button. Every time the user
chooses an item from the dropdown and clicks on the button i want that value
written below in list and allow user to select more.

Also how can these choices be saved somehow so tha when the user goes to the
next page the choices he made can be written to the database.

For example

The choices in the dropdown may be

London
Dublin
Paris
New York

When the user chooses Dublin I want ti written below the dropdown. Then when
he chooses New York. I want it added to london. so that it displays

Dublin
London

Then when he click next button these two choices are taken over to the next
page where an insert query can be used to insert them into the db.
 
R

Ray at

Well, one thing you could do is use a mulit-line select with the multiple
option that will let the users select multiple options. But, that is not
what you described. So, what you can do is post the page back to itself and
write the value of the selected item to a hidden input on the bottom of the
page. Then when the user selects another one and submits, add that
selection to the input as well. Keep doing that, and then when the user
selects the other submit button, the one that signifies he's finished, grab
the value of the select and the hidden input(s) for all the values.

Ray at work
 
J

John Beschler

Actually, I have implemented that exact scenario on one or
two of my pages.

Basically I have two select boxes with some size greater
than one (so that it will display more than one line).
Then I use javascript to copy the selected value from the
first select box to the second.
Then, when the page is submitted, I read the values in the
2nd select box and populate an array with that data using
javascript.
Next, again using javascript, I copy the contents of the
array to a hidden text field on the form.
Finally, I submit the form, again using javascript.

I know this sounds complicated, but there are no reposts,
or roundtrips to the server except for the final posting
of the form. The entries get added to the 2nd select box
immediately and they all get processed at one time when
the page gets submitted. I also have code to delete any
entry from the 2nd select box using roughly the same
process (in reverse).

Note: the reason for populating the array and not the
hidden text field directly is so that I can sort the
entries before processing the page - makes it a little
easier to check for duplicate entries when updateing the
SQL database. If you don't need to sort, you could
populate the text field directly from the select box.

HTH,
John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,906
Latest member
SkinfixSkintag

Latest Threads

Top