Jump to content

multiple select reading


mojito

Recommended Posts

Hi freaks

Im comming back into some form problems, i thought a multiple select form sent a comma separated values but when using and selecting multiple options the query string is like

select=me&select=too&Submit=Submit

do i have to iterate through each select and make an array myself?

thanks

mojito

Link to comment
Share on other sites

Try HTML: <select multiple name="myselectbox[]"> ... </select>

XHTML: <select multiple="multiple" name="myselectbox[]"> ... </select>


PHP:

$selections = $_GET['myselectbox']; // or $_POST

for ($i = 0, $cnt = count($selections); $i < $cnt; $i++) {

echo 'You selected: ', $selections[$i], '<br/>';

}

or:

$selections = $_GET['myselectbox']; // or $_POST

foreach ($selections as $choice) {

echo 'You selected: ', $choice, '<br/>';

}


Edit: Forgot "multiple" so I added it - thx kenrbnsn. I'm sure mojito has mutiple already specified since his post shows he's getting: select=me&select=too
Link to comment
Share on other sites

[!--quoteo(post=374714:date=May 17 2006, 04:31 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ May 17 2006, 04:31 PM) [snapback]374714[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Please post the souce for your form.

You need to make the name of the select list an array.
[code]<select name="select[]" multiple>[/code]

Ken
[/quote]

yer i tried that and the result is

select%5B%5D=me&select%5B%5D=too&Submit=Submit

so its just encoding the brackets, and not making an array.
here is my source
[code]<select name="select[]" size="2" multiple="multiple">
    <option value="me">1</option>
    <option value="too">2</option>
  </select>[/code]

m
Link to comment
Share on other sites

[!--quoteo(post=374788:date=May 17 2006, 02:24 PM:name=mojito)--][div class=\'quotetop\']QUOTE(mojito @ May 17 2006, 02:24 PM) [snapback]374788[/snapback][/div][div class=\'quotemain\'][!--quotec--]
yer i tried that and the result is

select%5B%5D=me&select%5B%5D=too&Submit=Submit

so its just encoding the brackets, and not making an array.

m
[/quote]
it will be an array if you try
[code]print_r($_GET['select']);[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.