1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<% include('/elements/xmlhttp.html',
'url' => $p.'misc/states.cgi',
'subs' => [ $opt{'prefix'}. 'get_states' ],
)
%>
<SCRIPT TYPE="text/javascript">
function opt(what,value,text) {
var optionName = new Option(text, value, false, false);
var length = what.length;
what.options[length] = optionName;
}
function <% $opt{'prefix'} %>country_changed(what, callback) {
country = what.options[what.selectedIndex].value;
function <% $opt{'prefix'} %>update_states(states) {
// blank the current state list
for ( var i = what.form.<% $opt{'prefix'} %>state.length; i >= 0; i-- )
what.form.<% $opt{'prefix'} %>state.options[i] = null;
// add the new states
var statesArray = eval('(' + states + ')' );
for ( var s = 0; s < statesArray.length; s=s+2 ) {
var stateLabel = statesArray[s+1];
if ( stateLabel == "" )
stateLabel = '(n/a)';
opt(what.form.<% $opt{'prefix'} %>state, statesArray[s], stateLabel);
}
//run the callback
if ( callback != null )
callback();
}
// go get the new states
<% $opt{'prefix'} %>get_states( country, <% $opt{'prefix'} %>update_states );
}
</SCRIPT>
<SELECT NAME="<% $opt{'prefix'} %>country" onChange="<% $opt{'prefix'} %>country_changed(this); <% $opt{'onchange'} %>" <% $opt{'disabled'} %>>
% foreach my $country (
% sort { ($b eq $countrydefault) <=> ($a eq $countrydefault)
% or code2country($a) cmp code2country($b) }
% map { $_->country }
% qsearch({
% 'select' => 'country',
% 'table' => 'cust_main_county',
% 'hashref' => {},
% 'extra_sql' => 'GROUP BY country',
% })
% ) {
<OPTION VALUE="<% $country %>"<% $country eq $opt{'country'} ? ' SELECTED' : '' %>><% code2country($country). " ($country)" %>
% }
</SELECT>
<%init>
my %opt = @_;
foreach my $opt (qw( county state country prefix onchange disabled )) {
$opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
}
my $conf = new FS::Conf;
my $countrydefault = $conf->config('countrydefault') || 'US';
</%init>
|