4 % foreach my $opt (qw( county state country prefix onchange disabled )) {
5 % $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
8 % my $conf = new FS::Conf;
9 % my $countrydefault = $conf->config('countrydefault') || 'US';
14 <% include('/elements/xmlhttp.html',
15 'url' => $p.'misc/states.cgi',
16 'subs' => [ $opt{'prefix'}. 'get_states' ],
20 <SCRIPT TYPE="text/javascript">
22 function opt(what,value,text) {
23 var optionName = new Option(text, value, false, false);
24 var length = what.length;
25 what.options[length] = optionName;
28 function <% $opt{'prefix'} %>country_changed(what, callback) {
30 country = what.options[what.selectedIndex].value;
32 function <% $opt{'prefix'} %>update_states(states) {
34 // blank the current state list
35 for ( var i = what.form.<% $opt{'prefix'} %>state.length; i >= 0; i-- )
36 what.form.<% $opt{'prefix'} %>state.options[i] = null;
39 var statesArray = eval('(' + states + ')' );
40 for ( var s = 0; s < statesArray.length; s=s+2 ) {
41 var stateLabel = statesArray[s+1];
42 if ( stateLabel == "" )
44 opt(what.form.<% $opt{'prefix'} %>state, statesArray[s], stateLabel);
48 if ( callback != null )
52 // go get the new states
53 <% $opt{'prefix'} %>get_states( country, <% $opt{'prefix'} %>update_states );
59 <SELECT NAME="<% $opt{'prefix'} %>country" onChange="<% $opt{'prefix'} %>country_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
60 % foreach my $country (
61 % sort { ($b eq $countrydefault) <=> ($a eq $countrydefault)
62 % or code2country($a) cmp code2country($b) }
64 % qsearch( 'cust_main_county',{}, 'DISTINCT ON ( country ) *', )
69 <OPTION VALUE="<% $country %>"<% $country eq $opt{'country'} ? ' SELECTED' : '' %>><% code2country($country). " ($country)" %>