5 <& /elements/select-city.html,
7 country => $current_country,
8 state => $current_state,
9 county => $current_county,
10 city => $current_city,
13 prefix => $optional_unique_prefix,
14 onchange => $javascript,
16 disable_empty => 1, #defaults to 1, set to 0 to disable the empty option
17 empty_label => 'all', #label for empty option
18 style => [ 'attribute:value', 'another:value' ],
24 <% include('/elements/xmlhttp.html',
25 'url' => $p.'misc/cities.cgi',
26 'subs' => [ $pre. 'get_cities' ],
30 <SCRIPT TYPE="text/javascript">
32 function opt(what,value,text) {
33 var optionName = new Option(text, value, false, false);
34 var length = what.length;
35 what.options[length] = optionName;
38 function <% $pre %>county_changed(what, callback) {
40 what.form.<% $pre %>city.disabled = 'disabled';
42 county = what.form.<% $pre %>county.options[what.form.<% $pre %>county.selectedIndex].value;
43 state = what.options[what.selectedIndex].value;
44 country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
46 function <% $pre %>update_cities(cities) {
48 // blank the current city list
49 for ( var i = what.form.<% $pre %>city.length; i >= 0; i-- )
50 what.form.<% $pre %>city.options[i] = null;
52 % unless ( $opt{disable_empty} ) {
53 opt( what.form.<% $pre %>city, '', <% $opt{empty_label} |js_string %> );
57 var citiesArray = eval('(' + cities + ')' );
58 for ( var s = 0; s < citiesArray.length; s++ ) {
59 var cityLabel = citiesArray[s];
60 if ( cityLabel == "" )
62 opt(what.form.<% $pre %>city, citiesArray[s], cityLabel);
65 var cityFormLabel = document.getElementById('<% $pre %>citylabel');
67 if ( citiesArray.length > 1 ) {
68 what.form.<% $pre %>city.style.display = '';
69 if ( cityFormLabel ) {
70 //cityFormLabel.style.visibility = 'visible';
71 cityFormLabel.style.display = '';
74 what.form.<% $pre %>city.style.display = 'none';
75 if ( cityFormLabel ) {
76 //cityFormLabel.style.visibility = 'hidden';
77 cityFormLabel.style.display = 'none';
81 what.form.<% $pre %>city.disabled = '';
84 if ( callback != null ) {
87 <% $pre %>city_changed(what.form.<% $pre %>city);
91 // go get the new cities
92 <% $pre %>get_cities( state, country, <% $pre %>update_cities );
98 <SELECT NAME = "<% $pre %>city"
100 onChange= "<% $onchange %>"
101 <% $opt{'disabled'} %>
105 % unless ( $opt{'disable_empty'} ) {
106 <OPTION VALUE="" <% $opt{county} eq '' ? 'SELECTED' : '' %>><% $opt{empty_label} %>
109 % foreach my $city ( @cities ) {
111 <OPTION VALUE="<% $city |h %>"
112 <% $city eq $opt{'city'} ? 'SELECTED' : '' %>
113 ><% $city eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $city %>
121 <SCRIPT TYPE="text/javascript">
122 function <% $pre %>city_changed(what) {
126 <SELECT NAME = "<% $pre %>city"
127 ID = "<% $pre %>city"
128 STYLE = "display:none"
130 <OPTION SELECTED VALUE="<% $opt{'city'} |h %>">
138 foreach my $opt (qw( city county state country prefix onchange disabled
140 $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
143 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
145 my $pre = $opt{'prefix'};
147 my $onchange = $opt{'onchange'};
149 my $city_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
154 @cities = map { length($_) ? $_ : $opt{'empty_data_value'} }
155 cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
157 push @$city_style, 'display:none'
158 unless scalar(@cities) > 1;
164 ? 'STYLE="'. join(';', @$city_style). '"'
170 my $sql = "SELECT COUNT(*) FROM cust_main_county".
171 " WHERE city IS NOT NULL AND city != ''";
172 my $sth = dbh->prepare($sql) or die dbh->errstr;
173 $sth->execute or die $sth->errstr;
174 my $cityflag = $sth->fetchrow_arrayref->[0];