4 foreach my $opt (qw( county state country prefix onchange disabled )) {
5 $opt{$_} = '' unless exists($opt{$_}) && defined($opt{$_});
8 my $sql = "SELECT COUNT(*) FROM cust_main_county".
9 " WHERE county IS NOT NULL AND county != ''";
10 my $sth = dbh->prepare($sql) or die dbh->errstr;
11 $sth->execute or die $sth->errstr;
12 my $countyflag = $sth->fetchrow_arrayref->[0];
16 <% if ( $countyflag ) { %>
18 <%= include('/elements/xmlhttp.html', $p.'misc/counties.cgi', $opt{'prefix'}. 'get_counties' ) %>
20 <SCRIPT TYPE="text/javascript">
22 function opt(what,value,text) {
23 var optionName = new Option(text, value, false, false);
24 var length = what.length;
25 what.options[length] = optionName;
28 function <%= $opt{'prefix'} %>state_changed(what, callback) {
30 state = what.options[what.selectedIndex].text;
31 country = what.form.<%= $opt{'prefix'} %>country.options[what.form.<%= $opt{'prefix'} %>country.selectedIndex].text;
33 function <%= $opt{'prefix'} %>update_counties(counties) {
35 // blank the current county list
36 for ( var i = what.form.<%= $opt{'prefix'} %>county.length; i >= 0; i-- )
37 what.form.<%= $opt{'prefix'} %>county.options[i] = null;
39 // add the new counties
40 var countiesArray = eval('(' + counties + ')' );
41 for ( var s = 0; s < countiesArray.length; s++ ) {
42 var countyLabel = countiesArray[s];
43 if ( countyLabel == "" )
44 countyLabel = '(n/a)';
45 opt(what.form.<%= $opt{'prefix'} %>county, countiesArray[s], countyLabel);
49 if ( callback != null )
53 // go get the new counties
54 <%= $opt{'prefix'} %>get_counties( state, country, <%= $opt{'prefix'} %>update_counties );
60 <SELECT NAME="<%= $opt{'prefix'} %>county" onChange="<%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
62 <% foreach my $county (
65 qsearch('cust_main_county', { 'state' => $opt{'state'},
66 'country' => $opt{'country'},
72 <OPTION VALUE="<%= $county %>"<%= $county eq $opt{'county'} ? ' SELECTED' : '' %>><%= $county %>
80 <SCRIPT TYPE="text/javascript">
81 function <%= $opt{'prefix'} %>state_changed(what) {
85 <INPUT TYPE="hidden" NAME="<%= $opt{'prefix'} %>county" VALUE="<%= $opt{'county'} %>">