Subject: | CGI.pm popup_menu multiple selects |
When you create a popup_menu with CGI.pm (ex: print my_popup_menu(-
name=>'selection_serverlist',-default=>'' ,-multiple=>'true',-
values=>\@ep, -labels=>\%serverlist);) and you use multiple=>'true'
you can select multiple items in the list and post them.
The problem in CGI.pm is that when you rebuild you page your selection
is lost.
The CGI.pm module doesn't work with the hash that's being returned.
It only uses the first item in the has.
As a quick-fix I changed the following:
foreach (@values) {
if (/<optgroup/) {
foreach (split(/\n/)) {
my $selectit = $XHTML ? 'selected="selected"' : 'selected';
s/(value="$selected")/$selectit $1/ if defined $selected;
$result .= "$_\n";
}
}
else {
my $temp_value = $_;
for ( $self->param($name)) {
if ($temp_value eq $_) {
$selected = $_;
}
}
my $attribs = $self->_set_attributes($_, $attributes);
my($selectit) = defined($selected) ? $self->_selected
($selected eq $_) : '';
my($label) = $_;
$label = $labels->{$_} if defined($labels) && defined($labels->
{$_});
my($value) = $self->escapeHTML($_);
$label=$self->escapeHTML($label,1);
$result .= "<option${attribs} ${selectit}
value=\"$value\">$label</option>\n";
}
}
The first 6 lines of the else are mine. They fix my problem with the
multiple select.
Kind regards,
Tom