5 include( '/elements/select-country.html',
7 country => $current_country,
10 prefix => $optional_unique_prefix,
11 onchange => $javascript,
13 disable_empty => 1, #defaults to 1, disable the empty option
14 empty_label => 'all', #label for empty option
15 disable_stateupdate => 0, #bool - disabled update of the select-state.html
16 style => [ 'attribute:value', 'another:value' ],
20 % unless ( $opt{'disable_stateupdate'} ) {
22 <% include('/elements/xmlhttp.html',
23 'url' => $p.'misc/states.cgi',
24 'subs' => [ $pre. 'get_states' ],
28 <SCRIPT TYPE="text/javascript">
30 function opt(what,value,text) {
31 var optionName = new Option(text, value, false, false);
32 var length = what.length;
33 what.options[length] = optionName;
36 function <% $pre %>country_changed(what, callback) {
38 country = what.options[what.selectedIndex].value;
40 function <% $pre %>update_states(states) {
42 // blank the current state list
43 for ( var i = what.form.<% $pre %>state.length; i >= 0; i-- )
44 what.form.<% $pre %>state.options[i] = null;
47 var statesArray = eval('(' + states + ')' );
48 for ( var s = 0; s < statesArray.length; s=s+2 ) {
49 var stateLabel = statesArray[s+1];
50 if ( stateLabel == "" )
52 opt(what.form.<% $pre %>state, statesArray[s], stateLabel);
56 if ( callback != null )
60 // go get the new states
61 <% $pre %>get_states( country, <% $pre %>update_states );
69 <SELECT NAME = "<% $pre %>country"
70 ID = "<% $pre %>country"
71 onChange = "<% $onchange %>"
72 <% $opt{'disabled'} %>
76 % unless ( $opt{'disable_empty'} ) {
77 <OPTION VALUE=""><% $opt{'empty_label'} || '(all)' %>
80 % foreach my $country ( @all_countries ) {
82 <OPTION VALUE="<% $country |h %>"
83 <% $country eq $opt{'country'} ? ' SELECTED' : '' %>
84 ><% code2country($country). " ($country)" %>
93 foreach my $opt (qw( country prefix onchange disabled disable_stateupdate )) {
94 $opt{$opt} = '' unless exists($opt{$opt}) && defined($opt{$opt});
97 $opt{'disable_empty'} = 1 unless exists($opt{'disable_empty'});
99 my $pre = $opt{'prefix'};
102 ( $opt{'disable_stateupdate'} ? '' : $pre.'country_changed(this); ' ).
105 $opt{'style'} ||= [];
107 scalar(@{$opt{style}})
108 ? 'STYLE="'. join(';', @{$opt{style}}). '"'
111 my $conf = new FS::Conf;
112 my $default = $conf->config('countrydefault') || 'US';
114 my @all_countries = (
115 sort { ($b eq $default) <=> ($a eq $default)
116 or code2country($a) cmp code2country($b)
120 'select' => 'country',
121 'table' => 'cust_main_county',
123 'extra_sql' => 'GROUP BY country',