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
17 style => [ 'attribute:value', 'another:value' ],
21 % if ( $countyflag ) {
23 <% include('/elements/xmlhttp.html',
24 'url' => $p.'misc/counties.cgi',
25 'subs' => [ $pre. 'get_counties' ],
29 <SCRIPT TYPE="text/javascript">
31 function opt(what,value,text) {
32 var optionName = new Option(text, value, false, false);
33 var length = what.length;
34 what.options[length] = optionName;
37 function <% $pre %>state_changed(what, callback) {
39 state = what.options[what.selectedIndex].value;
40 country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
42 function <% $pre %>update_counties(counties) {
44 // blank the current county list
45 for ( var i = what.form.<% $pre %>county.length; i >= 0; i-- )
46 what.form.<% $pre %>county.options[i] = null;
48 // add the new counties
49 var countiesArray = eval('(' + counties + ')' );
50 for ( var s = 0; s < countiesArray.length; s++ ) {
51 var countyLabel = countiesArray[s];
52 if ( countyLabel == "" )
53 countyLabel = '(n/a)';
54 opt(what.form.<% $pre %>county, countiesArray[s], countyLabel);
57 var countyFormLabel = document.getElementById('<% $pre %>countylabel');
59 if ( countiesArray.length > 1 ) {
60 what.form.<% $pre %>county.style.display = '';
61 //countyFormLabel.style.visibility = 'visible';
62 countyFormLabel.style.display = '';
64 what.form.<% $pre %>county.style.display = 'none';
65 //countyFormLabel.style.visibility = 'hidden';
66 countyFormLabel.style.display = 'none';
70 if ( callback != null )
74 // go get the new counties
75 <% $pre %>get_counties( state, country, <% $pre %>update_counties );
81 <SELECT NAME = "<% $pre %>county"
82 ID = "<% $pre %>county"
83 onChange= "<% $opt{'onchange'} %>"
84 <% $opt{'disabled'} %>
88 % unless ( $opt{'disable_empty'} ) {
89 <OPTION VALUE="" <% $opt{county} eq '' ? 'SELECTED' : '' %>><% $opt{empty_label} %>
92 % foreach my $county ( @counties ) {
94 <OPTION VALUE="<% $county |h %>"
95 <% $county eq $opt{'county'} ? 'SELECTED' : '' %>
96 ><% $county eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $county %>
104 <SCRIPT TYPE="text/javascript">
105 function <% $pre %>state_changed(what) {
109 <SELECT NAME = "<% $pre %>county"
110 ID = "<% $pre %>county"
111 STYLE = "display:none"
113 <OPTION SELECTED VALUE="<% $opt{'county'} |h %>">
121 foreach my $opt (qw( county state country prefix onchange disabled
123 $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
126 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
128 my $pre = $opt{'prefix'};
130 $opt{'style'} ||= [];
132 scalar(@{$opt{style}})
133 ? 'STYLE="'. join(';', @{$opt{style}}). '"'
139 @counties = map { length($_) ? $_ : $opt{'empty_data_value'} }
140 counties( $opt{'state'}, $opt{'country'} );
143 unless ( scalar(@counties) > 1 ) {
144 if ( $opt{'disabled'} =~ /STYLE=/i ) {
145 $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
147 $opt{'disabled'} .= ' STYLE="display:none"';
156 my $sql = "SELECT COUNT(*) FROM cust_main_county".
157 " WHERE county IS NOT NULL AND county != ''";
158 my $sth = dbh->prepare($sql) or die dbh->errstr;
159 $sth->execute or die $sth->errstr;
160 my $countyflag = $sth->fetchrow_arrayref->[0];