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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
<%
my %opt = @_;
foreach my $opt (qw( county state country prefix onchange disabled )) {
$opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
}
my $sql = "SELECT COUNT(*) FROM cust_main_county".
" WHERE county IS NOT NULL AND county != ''";
my $sth = dbh->prepare($sql) or die dbh->errstr;
$sth->execute or die $sth->errstr;
my $countyflag = $sth->fetchrow_arrayref->[0];
%>
<% if ( $countyflag ) { %>
<%= include('/elements/xmlhttp.html',
'url' => $p.'misc/counties.cgi',
'subs' => [ $opt{'prefix'}. 'get_counties' ],
)
%>
<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'} %>state_changed(what, callback) {
state = what.options[what.selectedIndex].text;
country = what.form.<%= $opt{'prefix'} %>country.options[what.form.<%= $opt{'prefix'} %>country.selectedIndex].text;
function <%= $opt{'prefix'} %>update_counties(counties) {
// blank the current county list
for ( var i = what.form.<%= $opt{'prefix'} %>county.length; i >= 0; i-- )
what.form.<%= $opt{'prefix'} %>county.options[i] = null;
// add the new counties
var countiesArray = eval('(' + counties + ')' );
for ( var s = 0; s < countiesArray.length; s++ ) {
var countyLabel = countiesArray[s];
if ( countyLabel == "" )
countyLabel = '(n/a)';
opt(what.form.<%= $opt{'prefix'} %>county, countiesArray[s], countyLabel);
}
//run the callback
if ( callback != null )
callback();
}
// go get the new counties
<%= $opt{'prefix'} %>get_counties( state, country, <%= $opt{'prefix'} %>update_counties );
}
</SCRIPT>
<SELECT NAME="<%= $opt{'prefix'} %>county" onChange="<%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
<% foreach my $county (
sort
map { $_->county }
qsearch('cust_main_county', { 'state' => $opt{'state'},
'country' => $opt{'country'},
}
)
) {
%>
<OPTION VALUE="<%= $county %>"<%= $county eq $opt{'county'} ? ' SELECTED' : '' %>><%= $county %>
<% } %>
</SELECT>
<% } else { %>
<SCRIPT TYPE="text/javascript">
function <%= $opt{'prefix'} %>state_changed(what) {
}
</SCRIPT>
<INPUT TYPE="hidden" NAME="<%= $opt{'prefix'} %>county" VALUE="<%= $opt{'county'} %>">
<% } %>
|