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

How do I extract multiple selectd values from the request object? 1

Status
Not open for further replies.

nybz

Programmer
Mar 18, 2004
19
0
0
US
I have set up a <select> with multiple options enabled. Once submitted how do I retrieve the values? Do they come in as an array or comma delimited string or what?
 
what parser: php/asp/jsp/cfm?


<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
hi manarth - i am sending it to a java servlet. thank you for your interest.
 
Ok, handle it with the doGet or doPost respomse, as matches the form.

Multiple select boxes are passed as arrays:
Code:
 String [] selections = req.getParameterValues("selectionoptions");

Don't forget, your user may not select anything, so test for null before trying to load the array :)

Here's a good web forms and servlets tutorial.

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Excellent - Thank you Manarth !!
And, I have earmarked the tutorial.
 
How would you handle this with PHP? I have this code:

<p><font face="Verdana"><small>Question 5 :</small><br>
<small><select name="champ5[]" size="2" multiple>
<option selected value="0">Choose</option>
<option value="Reponse5_1">1</option>
<option value="Reponse5_2">2</option>
<option value="Reponse5_3">3</option>
<option value="Reponse5_4">4</option>
<option value="Reponse5_5">5</option>
</select></small></font></p>

I know it's comma delimited when it comes back but how do I reference the string? I've tried $champ5 and that's not it???

Thanks in advance.
 
Your problem lies in the html: your select statement - <select name="champ5[]" size="2" multiple>.

You don't need to declare in the html that this represents an array.

Code:
<p><font face="Verdana"><small>Question 5 :</small><br>
        <small><select [COLOR=red]name="champ5"[/color] size="2" multiple>
         <option selected value="0">Choose</option>
         <option value="Reponse5_1">1</option>
         <option value="Reponse5_2">2</option>
         <option value="Reponse5_3">3</option>
         <option value="Reponse5_4">4</option>
         <option value="Reponse5_5">5</option>
        </select></small></font></p>

Your array name from this code will be $champ: $champ[0] represents the first chosen item; etc.

<marc> i wonder what will happen if i press this...[ul][li]please tell us if our suggestion has helped[/li][li]need some help? faq581-3339[/li][/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top