Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple multiple select boxes dynamically created.

Status
Not open for further replies.

justride

Programmer
Jan 9, 2004
251
US
I have a for which the user can add multiple fields dynamically, which allows them to expand for more entries.

most of the data is singgle values except one field which is a multiple select field.

so if the user wants 5 multiple select fields my html looks like

Code:
<select name="requirements[]" multiple size=10>
..
<select name="requirements[]" multiple size=10>
..
<select name="requirements[]" multiple size=10>
..
<select name="requirements[]" multiple size=10>
..
<select name="requirements[]" multiple size=10>

However the problem is then when the form is submitted, all the data is stored into one array instead of a 2 dimesnional array with data from each select in its own array.

Code:
	$requirements[] = $_POST['requirements[]'];

It's impossible to keep track of which data comes from which select box.

Any suggestions?

Thanks
Chris
 
I figured it out the html selects need to be like this..
where $i changes
<select name="requirements[$i]" multiple size=10>

$requirements[][] = $_POST['requirements[][]'];

I have to keep track of $i in a hidden field.

 
you can also use checkbox if a user is allowed to select more values of the same field
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top