Gmunky Posted September 7, 2006 Share Posted September 7, 2006 here is what I have. when two or more values are selected from the listbox, it only outputs the lowest selected value from the list.//script1<form action="script2.php" ?>" method="post"><select multiple="multiple" name="hrs"> <option value="10 hours">10 hours</option> <option value="20 hours">20 hours</option> <option value="30 hours">30 hours</option> <option value="40 hours">40 hours</option> </select><input type="submit" name="submit" value="Submit" /></form>//script2if (isset($_POST['submit'])) { $hrs=$_POST['hrs']; echo "hours week: $hrs <br>"; } Quote Link to comment Share on other sites More sharing options...
Barand Posted September 7, 2006 Share Posted September 7, 2006 Name you checkbox like this<select multiple="multiple" name="hrs[]">The multiple options are then posted in an array. Process as[code]foreach ($_POST['hrs'] as $value) { // do something with value echo "$value <br />";}[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted September 7, 2006 Share Posted September 7, 2006 You need to make the name of the input field an array:[code]<?phpif (isset($_POST['submit'])) echo '<pre>' . print_r($_POST,true) . '</pre>';?><html><head><title>Test Multiple</title></head><body><form method="post"><select multiple name="hrs[]"> <option value="10 hours">10 hours</option> <option value="20 hours">20 hours</option> <option value="30 hours">30 hours</option> <option value="40 hours">40 hours</option> </select><input type="submit" name="submit" value="Submit" /></form><?phpif (isset($_POST['submit'])) { $hrs=(is_array($_POST['hrs']))?implode(', ',$_POST['hrs']):$_POST['hrs']; echo "hours week:" . $hrs; }?></body></html>[/code]Notice this line: [color=red]<select multiple [b]name="hrs[]">[/b][/color]Ken Quote Link to comment Share on other sites More sharing options...
Gmunky Posted September 7, 2006 Author Share Posted September 7, 2006 thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.