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';
13 <%= include('/elements/xmlhttp.html',
14 'url' => $p.'misc/states.cgi',
15 'subs' => [ $opt{'prefix'}. 'get_states' ],
19 <SCRIPT TYPE="text/javascript">
21 function opt(what,value,text) {
22 var optionName = new Option(text, value, false, false);
23 var length = what.length;
24 what.options[length] = optionName;
27 function <%= $opt{'prefix'} %>country_changed(what, callback) {
29 country = what.options[what.selectedIndex].text;
31 function <%= $opt{'prefix'} %>update_states(states) {
33 // blank the current state list
34 for ( var i = what.form.<%= $opt{'prefix'} %>state.length; i >= 0; i-- )
35 what.form.<%= $opt{'prefix'} %>state.options[i] = null;
38 var statesArray = eval('(' + states + ')' );
39 for ( var s = 0; s < statesArray.length; s++ ) {
40 var stateLabel = statesArray[s];
41 if ( stateLabel == "" )
43 opt(what.form.<%= $opt{'prefix'} %>state, statesArray[s], stateLabel);
47 if ( callback != null )
51 // go get the new states
52 <%= $opt{'prefix'} %>get_states( country, <%= $opt{'prefix'} %>update_states );
58 <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) or $a cmp $b }
63 qsearch( 'cust_main_county',{}, 'DISTINCT ON ( country ) *', )
67 <OPTION VALUE="<%= $country %>"<%= $country eq $opt{'country'} ? ' SELECTED' : '' %>><%= $country %>