Listbox selections into an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Listbox selections into an array

Post by cturner »

I am just wondering if there is a way to put listbox selections into an array? Thanks in advance.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Re: Listbox selections into an array

Post by Ambush Commander »

Hi, what's a listbox? Do you mean <select multiple>? It will already be an array in the $_POST[$key]
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Re: Listbox selections into an array

Post by cturner »

I am wanting to calculate all of the selections that are made in the listbox. So I need more information.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Listbox selections into an array

Post by Jonah Bron »

Like this?

Code: Select all

foreach ($_POST as $key => $name){
  print $name;//the label of the $_POST part (e.g. $_POST['name'] or $_POST[1])
  print $key;//the content of the $_POST part
}
 
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Listbox selections into an array

Post by superdezign »

cturner wrote:I am wanting to calculate all of the selections that are made in the listbox. So I need more information.
Make the form, and print_r($_POST). That'll show you exactly what the data will look like.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Listbox selections into an array

Post by John Cartwright »

Assuming you were infact talking about the <select></select> element, upon submission you will only receive the selected index. One possibility is the use of javascript, perhaps in combination with XMLHttpRequest (Ajax).
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Listbox selections into an array

Post by superdezign »

Jcart wrote:Assuming you were infact talking about the <select></select> element, upon submission you will only receive the selected index.
Or in the case of giving the <select> element the 'multiple' attribute, the selected indexes.
Post Reply