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', $p.'misc/states.cgi', $opt{'prefix'}. 'get_states') %>
15 <SCRIPT TYPE="text/javascript">
17 function opt(what,value,text) {
18 var optionName = new Option(text, value, false, false);
19 var length = what.length;
20 what.options[length] = optionName;
23 function <%= $opt{'prefix'} %>country_changed(what, callback) {
25 country = what.options[what.selectedIndex].text;
27 function <%= $opt{'prefix'} %>update_states(states) {
29 // blank the current state list
30 for ( var i = what.form.<%= $opt{'prefix'} %>state.length; i >= 0; i-- )
31 what.form.<%= $opt{'prefix'} %>state.options[i] = null;
34 var statesArray = eval('(' + states + ')' );
35 for ( var s = 0; s < statesArray.length; s++ ) {
36 var stateLabel = statesArray[s];
37 if ( stateLabel == "" )
39 opt(what.form.<%= $opt{'prefix'} %>state, statesArray[s], stateLabel);
43 if ( callback != null )
47 // go get the new states
48 <%= $opt{'prefix'} %>get_states( country, <%= $opt{'prefix'} %>update_states );
54 <SELECT NAME="<%= $opt{'prefix'} %>country" onChange="<%= $opt{'prefix'} %>country_changed(this); <%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
56 <% foreach my $country (
57 sort { ($b eq $countrydefault) <=> ($a eq $countrydefault) or $a cmp $b }
59 qsearch( 'cust_main_county',{}, 'DISTINCT ON ( country ) *', )
63 <OPTION VALUE="<%= $country %>"<%= $country eq $opt{'country'} ? ' SELECTED' : '' %>><%= $country %>