5 include( '/elements/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, disable the empty option
17 # empty_label => 'all', #label for empty option
18 style => [ 'attribute:value', 'another:value' ],
23 <% include('/elements/xmlhttp.html',
24 'url' => $p.'misc/cities.cgi',
25 'subs' => [ $pre. 'get_cities' ],
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 var saved_<%$pre%>city= '<% $saved_city |h %>';
39 function <% $pre %>county_changed(what, callback) {
41 county = what.options[what.selectedIndex].value;
42 state = what.form.<% $pre %>state.options[what.form.<% $pre %>state.selectedIndex].value;
43 country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;
45 function <% $pre %>update_cities(cities) {
47 // blank the current city list
48 for ( var i = what.form.<% $pre %>city_select.length; i >= 0; i-- )
49 what.form.<% $pre %>city_select.options[i] = null;
52 var citiesArray = eval('(' + cities + ')' );
54 for ( var s = 0; s < citiesArray.length; s++ ) {
55 var cityLabel = citiesArray[s];
56 if ( cityLabel == "" )
58 opt(what.form.<% $pre %>city_select, citiesArray[s], cityLabel);
61 if ( citiesArray.length > 1 || citiesArray[0].length ) {
62 // turn off the text city, turn on the select
63 saved_<%$pre%>city = what.form.<%$ pre %>city.value;
64 <%$pre%>city_select_changed(what.form.<% $pre %>city_select);
65 what.form.<% $pre %>city.style.display = 'none';
66 what.form.<% $pre %>city_select.style.display = '';
67 } else if ( what.form.<% $pre %>city.style.display == 'none' ) {
68 // turn on the text city, turn off the select
69 what.form.<%$ pre %>city.value = saved_<%$pre%>city;
70 what.form.<% $pre %>city.style.display = '';
71 what.form.<% $pre %>city_select.style.display = 'none';
75 if ( callback != null )
79 // go get the new cities
80 <% $pre %>get_cities( county, state, country, <% $pre %>update_cities );
84 function <%$pre%>city_select_changed(what) {
85 what.form.<%$pre%>city.value = what.options[what.selectedIndex].value;
93 VALUE = "<% $opt{'city'} |h %>"
94 onChange = "<% $opt{'onchange'} %>"
95 <% $opt{'disabled'} %>
99 <SELECT NAME = "<%$pre%>city_select"
100 ID = "<%$pre%>city_select"
101 onChange = "<%$pre%>city_select_changed(this); <% $opt{'onchange'} %>"
102 <% $opt{'disabled'} %>
106 % foreach my $city ( @cities ) {
108 <OPTION VALUE="<% $city |h %>"
109 <% $city eq $opt{'city'} ? 'SELECTED' : '' %>
110 ><% $city eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $city %>
116 %# VALUE = "<% $curr_value |h %>"
121 my $pre = $opt{'prefix'};
123 my $text_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
124 my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
126 my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
128 if ( scalar(@cities) > 1 || $cities[0] ) {
129 push @$text_style, 'display:none';
131 push @$select_style, 'display:none';
132 $saved_city = $opt{'city'};
137 ? 'STYLE="'. join(';', @$text_style). '"'
141 scalar(@$select_style)
142 ? 'STYLE="'. join(';', @$select_style). '"'