Page 1 of 1

Listbox selections into an array

Posted: Sat Jan 12, 2008 4:01 pm
by cturner
I am just wondering if there is a way to put listbox selections into an array? Thanks in advance.

Re: Listbox selections into an array

Posted: Sat Jan 12, 2008 4:31 pm
by Ambush Commander
Hi, what's a listbox? Do you mean <select multiple>? It will already be an array in the $_POST[$key]

Re: Listbox selections into an array

Posted: Sat Jan 12, 2008 6:42 pm
by cturner
I am wanting to calculate all of the selections that are made in the listbox. So I need more information.

Re: Listbox selections into an array

Posted: Sat Jan 12, 2008 6:51 pm
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
}
 

Re: Listbox selections into an array

Posted: Sat Jan 12, 2008 11:02 pm
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.

Re: Listbox selections into an array

Posted: Sat Jan 12, 2008 11:21 pm
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).

Re: Listbox selections into an array

Posted: Sat Jan 12, 2008 11:28 pm
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.