I'm generating a <select multiple size=5> list.
After the form is submitted, I regenerate the list, but this time, the values the user selected in his multiple select are preloaded, saving the state of his last form submission.
I've got it all working, except for the fact that when reloading the select list, it skips the first "selected" and then writes the rest.
For instance, if you selected one from the list, it wouldn't reload any as selected. If you had selected two, it would mark as selected the second on you choose and so on. I must be looking right at the problem and don't see it.
Here is the code,
Thanks,
Don
Code: Select all
<?
// each select is first an array
$arr_pizza = array
(
'All' => '%',
'Cheese' => 'cheese',
'Combo' => 'combo',
'Veggie' => 'veggie'
);
?>
<hr>
<b>Hold down control while clicking selections</b><p>
<form action="<?php echo $HTTP_SERVER_VARSї'PHP_SELF']; ?>" method="post">
Pizza types: <p>
<select multiple name="pizzaї]" size=5>
<?
foreach ($arr_pizza as $key => $value)
{
if(!isset($_POSTї'set'])) // onLoad
{
echo "<option value="$value">$key _out</option>\n";
}
else // onSubmit
{
if(array_search($value,$_POSTї'pizza']))
{
echo "<option value="$value" selected>$key</option>\n";
}
else
{
echo "<option value="$value">$key _loop</option>\n";
}
}
}
?>
<option>----------------------------------------</option>
</select><br>
<input type="hidden" name="set" value="1">
<input type="submit" name="submit" value="submit">
</form>