Jump to content

Form List Box with Multiple Items Selected


rick2302

Recommended Posts

I am relatively new to PHP and have been working with using forms and can handle the basics. What I would like to do is have a list box on a form that enables multiple selections:<select name="activities" size="4" multiple><option value="0">No Preference</option><option value="1">Amusements</option><option value="2">Animal Attractions</option><option value="3">Art, Music & Theater</option><option value="4">Burial Grounds & Monuments</option><option value="5">Education & Research</option><option value="6">Historic Sites</option></select>I cannot seem to figure out a way to hand off the selection(s) to PHP. If the user selects one, no problem, if they select more than one, I am stuck - only one value comes across.Thanks!

Link to comment
Share on other sites

Got it.File name of code below = rickTest.php:

<?php$_nameis = $_POST['name'];$_ageis = $_POST['age'];$_activities = $_POST['activities'];echo "name = " .$_nameis;echo "<br />";echo "age = " .$_ageis;echo "<br />";echo "activities = " .$_activities;echo "<br />";echo "activities0 = " .$_activities[0];echo "<br />";echo "activities1 = " .$_activities[1];echo "<br />";echo "activities2 = " .$_activities[2];?><form action="rickTest.php" method="post">Enter your name: <input type="text" name="name" /><br />Enter your age: <input type="text" name="age" /><br />MultiSelect:<select name="activities[]" size="5" multiple><option value="noPref">No Preference</option><option value="amuse">Amusements</option><option value="animal">Animal Attractions</option><option value="art">Art, Music & Theater</option><option value="burial">Burial Grounds & Monuments</option><option value="ed">Education & Research</option><option value="hist">Historic Sites</option></select><input type="submit" /></form>

Hope this is helpful to others!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...