Forums

PHP

This topic is locked

menus/lists

Posted 09 Oct 2001 17:06:12
1
has voted
09 Oct 2001 17:06:12 Keith Slater posted:
Hey.. Im trying to make a list of a bunch of different things to choose from and I want to be able to select multiple ones. When they select more then one and submit it it only submits one and not all the ones I select.. Whats the easiest way to do that??

thanks!!!

Keith Slater

Replies

Replied 09 Oct 2001 17:55:06
09 Oct 2001 17:55:06 Tim Green replied:
Keith your post is a little ambiguous, please can you be a bit clearer ?

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 09 Oct 2001 19:14:55
09 Oct 2001 19:14:55 Keith Slater replied:
hmm ok let me try hehe...
I have a list box with like 15 different things to pick from. They can pick multiple things from the list box also. THe problem I'm having is when they select multiple options from the box it only submits one. I know it can be done because I've seen it.

thanks again

Keith Slater
Replied 09 Oct 2001 22:16:38
09 Oct 2001 22:16:38 Bruno Mairlot replied:
Keith,

it is normal, since when you post your form, only one of the selected value are passed.

So you must set up a JavaScript that will concatenate all the selected value of your &lt;select&gt; into a hidden input that will contain the real value, then you submit the form with JavaScript.

In your PHP code, you will explode() your hidden value into an array that will contains all the values the user selected.

Hope it helps.

If you need more info, post your code and let's have a look.

Bruno

"First they laugh at you, then they fight you, then you Win..." Ghandi
Replied 09 Oct 2001 23:03:57
09 Oct 2001 23:03:57 Keith Slater replied:
Ah ok I see what your saying will I be able to do delimited stuff with it like put comas between each selection then return it delimited or anything like that??
Here is one of the &lt;select&gt;'s

&lt;select tabindex="16" name="inside" size=5 multiple&gt;
&lt;option value="Air Conditioning"&gt;Air conditioning &lt;/option&gt;
&lt;option value="Basement"&gt;Basement &lt;/option&gt;
&lt;option value="Cable Ready"&gt;Cable ready &lt;/option&gt;
&lt;option value="Central Air"&gt;Central Air &lt;/option&gt;
&lt;option value="Dishwasher"&gt;Dishwasher &lt;/option&gt;
&lt;option value="Disposer"&gt;Disposer &lt;/option&gt;
&lt;option value="Eat in Kitchen"&gt;Eat in kitchen &lt;/option&gt;
&lt;option value="Eating Area"&gt;Eating area &lt;/option&gt;
&lt;option value="Elavator"&gt;Elevator &lt;/option&gt;
&lt;option value="Family Room"&gt;Family Room &lt;/option&gt;
&lt;option value="Fire Place"&gt;Fire Place &lt;/option&gt;
&lt;option value="Forced Air Heating"&gt;Forced air heating &lt;/option&gt;
&lt;option value="Formal Dining Room"&gt;Formal dining room &lt;/option&gt;
&lt;option value="Handicapped Accessible"&gt;Handicapped accessible &lt;/option&gt;
&lt;option value="Hardwood Floors"&gt;Hardwood floors &lt;/option&gt;
&lt;option value="Laundry Room"&gt;Laundry room in building &lt;/option&gt;
&lt;option value="Master Bedroom"&gt;Master Bedroom &lt;/option&gt;
&lt;option value="Microwave"&gt;Microwave &lt;/option&gt;
&lt;option value="Paid Utilities"&gt;Paid utilities &lt;/option&gt;
&lt;option value="Pets Allowed"&gt;Pets allowed &lt;/option&gt;
&lt;option value="Security System"&gt;Security system &lt;/option&gt;
&lt;option value="Storage Space"&gt;Storage space &lt;/option&gt;
&lt;option value="Washer/Dryer"&gt;Washer/dryer in unit &lt;/option&gt;
&lt;option value="Workshop"&gt;Workshop &lt;/option&gt;
&lt;/select&gt;

Keith Slater
Replied 09 Oct 2001 23:29:13
09 Oct 2001 23:29:13 Bruno Mairlot replied:
Yes sure,

as long as there isn't any comma into the &lt;select&gt; values you can use comma.

When doing this, I usually use | since it is a very rare character, so it doesn't pose any problems.

--- Better to die trying, than never try at all ---
Replied 10 Oct 2001 14:57:05
10 Oct 2001 14:57:05 Keith Slater replied:
ok cool. How would I do the | thing then?? Also do you know where I can find a sample of that javascript??

Thanks a lot!!!

Keith Slater
Replied 10 Oct 2001 14:59:37
10 Oct 2001 14:59:37 chief monkey replied:

You can recieve multiple values from a form object with PHP first a few things you must add for example your opening tag would be
&lt;select name="yourname[]" multiple&gt;
The brakets ([]) tell PHP to expect an array, the mutiple tag lets the user select more than one option.
Once submited you can treat it like any other array i.e
if (is_array($yourname)) {
echo"Your form values&lt;br&gt;";
while(list($key, $value) = each($yourname))
{
echo $value . "&lt;br&gt;\n";
}
}

Everybody has got to be somewhere

Reply to this topic