2 <% include('/elements/xmlhttp.html',
3 'url' => $p.'misc/states.cgi',
4 'subs' => [ $opt{'prefix'}. 'get_states' ],
8 <SCRIPT TYPE="text/javascript">
10 function opt(what,value,text) {
11 var optionName = new Option(text, value, false, false);
12 var length = what.length;
13 what.options[length] = optionName;
16 function <% $opt{'prefix'} %>country_changed(what, callback) {
18 country = what.options[what.selectedIndex].value;
20 function <% $opt{'prefix'} %>update_states(states) {
22 // blank the current state list
23 for ( var i = what.form.<% $opt{'prefix'} %>state.length; i >= 0; i-- )
24 what.form.<% $opt{'prefix'} %>state.options[i] = null;
27 var statesArray = eval('(' + states + ')' );
28 for ( var s = 0; s < statesArray.length; s=s+2 ) {
29 var stateLabel = statesArray[s+1];
30 if ( stateLabel == "" )
32 opt(what.form.<% $opt{'prefix'} %>state, statesArray[s], stateLabel);
36 if ( callback != null )
40 // go get the new states
41 <% $opt{'prefix'} %>get_states( country, <% $opt{'prefix'} %>update_states );
47 <SELECT NAME="<% $opt{'prefix'} %>country" onChange="<% $opt{'prefix'} %>country_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
49 % foreach my $country (
50 % sort { ($b eq $countrydefault) <=> ($a eq $countrydefault)
51 % or code2country($a) cmp code2country($b) }
54 % 'select' => 'country',
55 % 'table' => 'cust_main_county',
57 % 'extra_sql' => 'GROUP BY country',
61 <OPTION VALUE="<% $country %>"<% $country eq $opt{'country'} ? ' SELECTED' : '' %>><% code2country($country). " ($country)" %>
69 foreach my $opt (qw( county state country prefix onchange disabled )) {
70 $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
73 my $conf = new FS::Conf;
74 my $countrydefault = $conf->config('countrydefault') || 'US';