You're right, the global in that post is not working.... try this global (called country_select):
my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'United_States';
my @list = qw(
Afghanistan
Albania
Algeria
American_Samoa
Andorra
..............
Zambia
Zimbabwe
);
my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };
my $return = qq|<select name="$element_name"> |;
foreach my $country ( @list ) {
my $ischosen = $selected->{$country} ? ' selected="selected"' : '';
(my $country_nice = $country) =~ s,_, ,g;
$return .= qq|<option value ="$country" $ischosen>$country_nice</option>|;
}
$return .= q|</select>|;
return $return;
}and use it as
<%country_select('Country',$Country,'France')%>
The first argument is the name of the select box, the second is there to display what is already selected, and the third can be used to set a default value (if nothing is selected).
Hope this works better...
Ivan
-----
Iyengar Yoga Resources / GT Plugins
Code:
sub { my $element_name = shift;
my $selected_value = shift;
my $default_value = shift || 'United_States';
my @list = qw(
Afghanistan
Albania
Algeria
American_Samoa
Andorra
..............
Zambia
Zimbabwe
);
my $selected = $selected_value || $default_value;
$selected = { map {($_=>1)} ref $selected ? @$selected : $selected };
my $return = qq|<select name="$element_name"> |;
foreach my $country ( @list ) {
my $ischosen = $selected->{$country} ? ' selected="selected"' : '';
(my $country_nice = $country) =~ s,_, ,g;
$return .= qq|<option value ="$country" $ischosen>$country_nice</option>|;
}
$return .= q|</select>|;
return $return;
}
<%country_select('Country',$Country,'France')%>
The first argument is the name of the select box, the second is there to display what is already selected, and the third can be used to set a default value (if nothing is selected).
Hope this works better...
Ivan
-----
Iyengar Yoga Resources / GT Plugins