Hey MAGSGQ,
I had a crack at it and came up with the following. I really hope it's what you wanted because it took me a while to figure out.
Modifying
build_select_field_from_db would have been too hard, so I've made a new sub-routine instead.
Copy the new sub-routine into
html.pl and use the code
&combo_box; whenever you want to display it.
You will need to configure 3 things which are in
red:
- Change
STATE# to the
number of your "State" field
- Change
CITY# to the
number of your "City" field
Anyway, here it is (apologies for the horizontal scrolling):
Code:
sub combo_box {
# --------------------------------------------------------
# Combo box
#
my $count = 0;
my (%states, @line, $first);
print '<form name="combobox"><select name="state" onChange="redirect(this.options.selectedIndex)">';
open (DB, "<$db_file_name") or &cgierr($!);
if ($db_use_flock) { flock(DB, 1); }
while (<DB>) {
@line = &split_decode($_);
$states{$line[STATE#]}->{$line[CITY#]} = '';
$first = $line[STATE#] unless ($first);
$count++;
}
close DB;
foreach $state (sort(keys(%states))) {
print '<option>' . $state;
}
print "</select>\n<select name=\"city\">";
foreach $city (sort(keys(%{$states{$first}}))) {
print '<option>' . $city;
}
print qq~
</select>
<input type="button" name="test" value="Go!" onClick="go();">
<script language="javascript">
<!--
var groups = document.combobox.state.options.length;
var group = new Array(groups);
for (j=0;j<groups;j++) { group[j]=new Array(); }
~;
my ($count1, $count2) = 0;
foreach $state (sort(keys(%states))) {
$count2 = 0;
foreach $city (sort(keys(%{$states{$state}}))) {
print qq~group[$count1][$count2]=new Option("$city","$city")\n~;
$count2++;
}
$count1++;
}
print qq~
var form = document.combobox;
var temp = form.city;
function redirect(x) {
for (m=temp.options.length-1;m>0;m--) { temp.options[m] = null; }
for (j=0;j<group[x].length;j++){ temp.options[j] = new Option(group[x][j].text,group[x][j].value); }
temp.options[0].selected = true;
}
function go() {
var state = form.state.options[form.state.selectedIndex].text;
var city = form.city.options[form.city.selectedIndex].text;
var url = '$db_script_link_url&view_records=1&State='+state+'&City='+city;
location = url;
}
//-->
</script>
~;
}Let me know how it goes.
- Mark
Astro-Boy!!
http://www.zip.com.au/~astroboy/