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',
19 'url' => $p.'misc/counties.cgi',
20 'subs' => [ $opt{'prefix'}. 'get_counties' ],
24 <SCRIPT TYPE="text/javascript">
26 function opt(what,value,text) {
27 var optionName = new Option(text, value, false, false);
28 var length = what.length;
29 what.options[length] = optionName;
32 function <%= $opt{'prefix'} %>state_changed(what, callback) {
34 state = what.options[what.selectedIndex].text;
35 country = what.form.<%= $opt{'prefix'} %>country.options[what.form.<%= $opt{'prefix'} %>country.selectedIndex].text;
37 function <%= $opt{'prefix'} %>update_counties(counties) {
39 // blank the current county list
40 for ( var i = what.form.<%= $opt{'prefix'} %>county.length; i >= 0; i-- )
41 what.form.<%= $opt{'prefix'} %>county.options[i] = null;
43 // add the new counties
44 var countiesArray = eval('(' + counties + ')' );
45 for ( var s = 0; s < countiesArray.length; s++ ) {
46 var countyLabel = countiesArray[s];
47 if ( countyLabel == "" )
48 countyLabel = '(n/a)';
49 opt(what.form.<%= $opt{'prefix'} %>county, countiesArray[s], countyLabel);
53 if ( callback != null )
57 // go get the new counties
58 <%= $opt{'prefix'} %>get_counties( state, country, <%= $opt{'prefix'} %>update_counties );
64 <SELECT NAME="<%= $opt{'prefix'} %>county" onChange="<%= $opt{'onchange'} %>" <%= $opt{'disabled'} %>>
66 <% foreach my $county (
69 qsearch('cust_main_county', { 'state' => $opt{'state'},
70 'country' => $opt{'country'},
76 <OPTION VALUE="<%= $county %>"<%= $county eq $opt{'county'} ? ' SELECTED' : '' %>><%= $county %>
84 <SCRIPT TYPE="text/javascript">
85 function <%= $opt{'prefix'} %>state_changed(what) {
89 <INPUT TYPE="hidden" NAME="<%= $opt{'prefix'} %>county" VALUE="<%= $opt{'county'} %>">