Page 1 of 1

List element in a Form

Posted: Thu Oct 03, 2002 9:24 pm
by Zoram
I am trying to get a List to work so that the user can select several of the options and it saves that as the field... anyway, here is what i got.

Code: Select all

<select name="sizes" size="3" multiple id="sizes">
          <option value="XS">XS</option>
          <option value="S">S</option>
          <option value="M">M</option>
          <option value="L">L</option>
          <option value="XL">XL</option>
          <option value="XXL">XXL</option>
          <option value="XXXL">XXXL</option>
        </select>
How would i make it so that it stores all the options selected in the following format?

Code: Select all

(say i selected : S, M, XXL)
$sizes = S, M, XXL;
Thanks!

Posted: Thu Oct 03, 2002 9:32 pm
by hob_goblin

Code: Select all

$picked = "";
foreach($sizes as $value){
$picked .= " ".$value.",";
}
$picked = trim($picked, ",");
try something like that...

Posted: Thu Oct 03, 2002 9:54 pm
by Zoram
would that be on the page that i insert it into the table?

Posted: Thu Oct 03, 2002 9:56 pm
by mr_griff
You will also need to change the name attribute in your select tag be sizes[] (<- note the square brackets) so that it will be an array after the form is submitted. Then use the code hob_goblin posted.

Posted: Thu Oct 03, 2002 10:00 pm
by Zoram
alright, that works but it didn't trim that last ,

Posted: Thu Oct 03, 2002 10:21 pm
by mr_griff