<%doc> Example: <& /elements/select-county.html, #recommended country => $current_country, state => $current_state, county => $current_county, #optional prefix => $optional_unique_prefix, onchange => $javascript, disabled => 0, #bool disable_empty => 1, #defaults to 1, set to 0 to disable the empty option empty_label => 'all', #label for empty option style => [ 'attribute:value', 'another:value' ], &> % if ( $countyflag ) { <% include('/elements/xmlhttp.html', 'url' => $p.'misc/counties.cgi', 'subs' => [ $pre. 'get_counties' ], ) %> % } else { % } <%init> my %opt = @_; foreach my $opt (qw( county state country prefix onchange disabled empty_value )) { $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt}); } $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'}); my $pre = $opt{'prefix'}; # disable_cityupdate? my $onchange = ( $opt{'disable_cityupdate'} ? '' : $pre.'county_changed(this); ' ). $opt{'onchange'}; my $county_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : []; my @counties = (); if ( $countyflag ) { @counties = map { length($_) ? $_ : $opt{'empty_data_value'} } counties( $opt{'state'}, $opt{'country'} ); push @$county_style, 'display:none' unless scalar(@counties) > 1; } my $style = scalar(@$county_style) ? 'STYLE="'. join(';', @$county_style). '"' : ''; <%once> my $sql = "SELECT COUNT(*) FROM cust_main_county". " WHERE county IS NOT NULL AND county != ''"; my $sth = dbh->prepare($sql) or die dbh->errstr; $sth->execute or die $sth->errstr; my $countyflag = $sth->fetchrow_arrayref->[0];