3 <% include('/elements/xmlhttp.html',
4 'url' => $p.'misc/counties.cgi',
5 'subs' => [ $opt{'prefix'}. 'get_counties' ],
9 <SCRIPT TYPE="text/javascript">
11 function opt(what,value,text) {
12 var optionName = new Option(text, value, false, false);
13 var length = what.length;
14 what.options[length] = optionName;
17 function <% $opt{'prefix'} %>state_changed(what, callback) {
19 state = what.options[what.selectedIndex].value;
20 country = what.form.<% $opt{'prefix'} %>country.options[what.form.<% $opt{'prefix'} %>country.selectedIndex].value;
22 function <% $opt{'prefix'} %>update_counties(counties) {
24 // blank the current county list
25 for ( var i = what.form.<% $opt{'prefix'} %>county.length; i >= 0; i-- )
26 what.form.<% $opt{'prefix'} %>county.options[i] = null;
28 // add the new counties
29 var countiesArray = eval('(' + counties + ')' );
30 for ( var s = 0; s < countiesArray.length; s++ ) {
31 var countyLabel = countiesArray[s];
32 if ( countyLabel == "" )
33 countyLabel = '(n/a)';
34 opt(what.form.<% $opt{'prefix'} %>county, countiesArray[s], countyLabel);
37 var countyFormLabel = document.getElementById('<% $opt{'prefix'} %>countylabel');
39 if ( countiesArray.length > 1 ) {
40 what.form.<% $opt{'prefix'} %>county.style.display = '';
41 countyFormLabel.style.visibility = 'visible';
43 what.form.<% $opt{'prefix'} %>county.style.display = 'none';
44 countyFormLabel.style.visibility = 'hidden';
48 if ( callback != null )
52 // go get the new counties
53 <% $opt{'prefix'} %>get_counties( state, country, <% $opt{'prefix'} %>update_counties );
59 <SELECT NAME="<% $opt{'prefix'} %>county" onChange="<% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
61 % foreach my $county ( @counties ) {
63 <OPTION VALUE="<% $county %>"<% $county eq $opt{'county'} ? ' SELECTED' : '' %>><% $county %>
72 <SCRIPT TYPE="text/javascript">
73 function <% $opt{'prefix'} %>state_changed(what) {
77 <INPUT TYPE="hidden" NAME="<% $opt{'prefix'} %>county" VALUE="<% $opt{'county'} %>">
84 foreach my $opt (qw( county state country prefix onchange disabled )) {
85 $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
91 @counties = counties( $opt{'state'}, $opt{'country'} );
94 unless ( scalar(@counties) > 1 ) {
95 if ( $opt{'disabled'} =~ /STYLE=/i ) {
96 $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
98 $opt{'disabled'} .= ' STYLE="display:none"';
107 my $sql = "SELECT COUNT(*) FROM cust_main_county".
108 " WHERE county IS NOT NULL AND county != ''";
109 my $sth = dbh->prepare($sql) or die dbh->errstr;
110 $sth->execute or die $sth->errstr;
111 my $countyflag = $sth->fetchrow_arrayref->[0];