Listbox selections into an array
Moderator: General Moderators
Listbox selections into an array
I am just wondering if there is a way to put listbox selections into an array? Thanks in advance.
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
Re: Listbox selections into an array
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
I am wanting to calculate all of the selections that are made in the listbox. So I need more information.
- Jonah Bron
- DevNet Master
- Posts: 2764
- Joined: Thu Mar 15, 2007 6:28 pm
- Location: Redding, California
Re: Listbox selections into an array
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
}
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Listbox selections into an array
Make the form, and print_r($_POST). That'll show you exactly what the data will look like.cturner wrote:I am wanting to calculate all of the selections that are made in the listbox. So I need more information.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Listbox selections into an array
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).
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Re: Listbox selections into an array
Or in the case of giving the <select> element the 'multiple' attribute, the selected indexes.Jcart wrote:Assuming you were infact talking about the <select></select> element, upon submission you will only receive the selected index.