noname76
12-02-2004, 04:39 AM
I got the following function that builds a select box from an array:
function buildDropDownSelectBox($default,$items_array,$select_name) {
$html.='<select name="'.$select_name.'"'.$multiple.' class="form">';
while (list($offset, $zone) = @each($items_array)) {
$selected = ($offset == $default) ? ' selected' : '';
$html.='<option value="'.$offset.'"'.$selected.'>'.$zone.'</option>';
}
$html.='</select>';
reset($items_array);
return $html;
}
If user selects an item and posts the form with wrong data this function marks the item selected, so user doesn't have to select it again. ($default equals $_POST[name_of_the_box]).
Well, it works fine, but I want to do the same with a multiple select box. Can anyone tell me how to modify the code above in order to work with multiple boxes also?
Thanks in advance.
function buildDropDownSelectBox($default,$items_array,$select_name) {
$html.='<select name="'.$select_name.'"'.$multiple.' class="form">';
while (list($offset, $zone) = @each($items_array)) {
$selected = ($offset == $default) ? ' selected' : '';
$html.='<option value="'.$offset.'"'.$selected.'>'.$zone.'</option>';
}
$html.='</select>';
reset($items_array);
return $html;
}
If user selects an item and posts the form with wrong data this function marks the item selected, so user doesn't have to select it again. ($default equals $_POST[name_of_the_box]).
Well, it works fine, but I want to do the same with a multiple select box. Can anyone tell me how to modify the code above in order to work with multiple boxes also?
Thanks in advance.