5 include( '/elements/select-county.html',
7 country => $current_country,
8 state => $current_state,
9 county => $current_county,
12 prefix => $optional_unique_prefix,
13 onchange => $javascript,
15 disable_empty => 1, #defaults to 1, disable the empty option
16 empty_label => 'all', #label for empty option
20 % if ( $countyflag ) {
22 <% include('/elements/xmlhttp.html',
23 'url' => $p.'misc/counties.cgi',
24 'subs' => [ $pre. 'get_counties' ],
28 <SCRIPT TYPE="text/javascript">
30 function opt(what,value,text) {
31 var optionName = new Option(text, value, false, false);
32 var length = what.length;
33 what.options[length] = optionName;
36 function <% $pre %>state_changed(what, callback) {
38 state = what.options[what.selectedIndex].value;
39 country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
41 function <% $pre %>update_counties(counties) {
43 // blank the current county list
44 for ( var i = what.form.<% $pre %>county.length; i >= 0; i-- )
45 what.form.<% $pre %>county.options[i] = null;
47 // add the new counties
48 var countiesArray = eval('(' + counties + ')' );
49 for ( var s = 0; s < countiesArray.length; s++ ) {
50 var countyLabel = countiesArray[s];
51 if ( countyLabel == "" )
52 countyLabel = '(n/a)';
53 opt(what.form.<% $pre %>county, countiesArray[s], countyLabel);
56 var countyFormLabel = document.getElementById('<% $pre %>countylabel');
58 if ( countiesArray.length > 1 ) {
59 what.form.<% $pre %>county.style.display = '';
60 countyFormLabel.style.visibility = 'visible';
62 what.form.<% $pre %>county.style.display = 'none';
63 countyFormLabel.style.visibility = 'hidden';
67 if ( callback != null )
71 // go get the new counties
72 <% $pre %>get_counties( state, country, <% $pre %>update_counties );
78 <SELECT NAME = "<% $pre %>county"
79 ID = "<% $pre %>county"
80 onChange= "<% $opt{'onchange'} %>"
81 <% $opt{'disabled'} %>
84 % unless ( $opt{'disable_empty'} ) {
85 <OPTION VALUE="" <% $opt{county} eq '' ? 'SELECTED' : '' %>><% $opt{empty_label} %>
88 % foreach my $county ( @counties ) {
90 <OPTION VALUE="<% $county |h %>"
91 <% $county eq $opt{'county'} ? 'SELECTED' : '' %>
92 ><% $county eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $county %>
100 <SCRIPT TYPE="text/javascript">
101 function <% $pre %>state_changed(what) {
105 <SELECT NAME = "<% $pre %>county"
106 ID = "<% $pre %>county"
107 STYLE = "display:none"
109 <OPTION SELECTED VALUE="<% $opt{'county'} |h %>">
117 foreach my $opt (qw( county state country prefix onchange disabled
119 $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
122 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
124 my $pre = $opt{'prefix'};
129 @counties = map { length($_) ? $_ : $opt{'empty_data_value'} }
130 counties( $opt{'state'}, $opt{'country'} );
133 unless ( scalar(@counties) > 1 ) {
134 if ( $opt{'disabled'} =~ /STYLE=/i ) {
135 $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
137 $opt{'disabled'} .= ' STYLE="display:none"';
146 my $sql = "SELECT COUNT(*) FROM cust_main_county".
147 " WHERE county IS NOT NULL AND county != ''";
148 my $sth = dbh->prepare($sql) or die dbh->errstr;
149 $sth->execute or die $sth->errstr;
150 my $countyflag = $sth->fetchrow_arrayref->[0];