PerlJunkie45 has asked for the wisdom of the Perl Monks concerning the following question:

Monks,
I've come to ask for help to something i thought i could do pretty easily but writing it out, i couldn't figure it out.
I'm trying to write a cgi script that will query a database table for a list, then display them as a dropdown box, which i've done before, but now i want to take the value from box A and use it to query the table again, displaying items that match the entry in box A.

Example:
Drop-down box A will have a list of pools (group of machines) once a pool is selected, i want to use that value to query the database and display hostnames associated with that pool in Drop down box B.

After that, i will have some static drop downs that will be ready for submit since i want to take all the values and do something with them.
I've seen tons of web forms where once i select something in the first drop down box, a second appears with info for me to select. I can't seem to come up with a flow/logic on how i can do that without adding some sort of javascript. Can anyone shed light on this?
I would greatly appreciate it.
Thanks,
PJ45

Here's what my code looks like now; its pretty incomplete, but it querys the database table to get information to create the values for the first dropdown.
i've changed some information on this post from what's in my script just to be safe, i.e. db name, table name, password, rules, vips etc.

sorry if that sounds like a dumb request. I just feel stuck without any guidance. Any help would be greatly appreciated.
Thanks again.
#!/usr/local/bin/perl -w ################ # Ray Espinoza # version: 0.1 # 6/29/04 ################# use strict; use DBI; use CGI qw(:standard); my ($pool, $host, $vip, $rule); ############## # Start HTML # ############## print header (), start_html (-title => "Rule Change Tool", -bgcolor => "#6666CC +", -text => "black"), h2("Rule Change Tool"); ######################## # grab database handle # ######################## my $dbh = &connect; ############## # main logic # ############## my $view = lc (param("view")); if($view eq "") { show_pools($dbh); } ######## # SUBS # ######## ################ sub show_pools { ################ my $dbh = shift; my $value = "pool"; my $poollist_ref = get_lookup_values($dbh, $value); print strong ("Resonate Rule Entry Form"), start_form (-action => url ()), table ( Tr ( td ("Pool: "), td (popup_menu (-name => "pool", -values =>$poollist_ref)) ), Tr ( td ("Hosts: "), br (), td (popup_menu (-name => "hosts", -values => [""])) ), Tr ( td ("VIP: "), td (popup_menu (-name => "vip", -values => ["", "home", "www"], -default => [""], -override => 1)) ), Tr ( td ("Rule: "), td (popup_menu (-name => "rule", -values => ["", "test", "test1", "test2", "test3"], -default => [""], -override => 1)) ), ), br (), submit (-name => "choice", -value => "Submit"), end_form (); } ####################### sub get_lookup_values { ####################### my ($dbh, $query) = @_; my ($sth, @val, $label_ref); $sth = $dbh->prepare(qq{ SELECT DISTINCT $query from table ORD +ER by $query }); $sth->execute (); # check whether or not query returns a label column $label_ref = {} if $sth->{NUM_OF_FIELDS} > 1; while (my @row = $sth->fetchrow_array ()) { push (@val, $row[0]); $label_ref->{$row[0]} = $row[1] if $label_ref; # add +label map entry } $sth->finish (); return (wantarray () ? (\@val, $label_ref) : \@val); } ############# sub connect { ############# use DBI; my ($dbh, $sth, $count); $dbh= DBI->connect("DBI:mysql:host=localhost;database=database","datab +aseuser","databasepassword",{PrintError => 0, RaiseError => 1}); return $dbh; }

Replies are listed 'Best First'.
Re: Ideas for Logic to fill out this form
by BUU (Prior) on Jun 28, 2004 at 23:20 UTC
    If you want the client's screen to be modified without a trip the server you have to use javascript. Thats kind of the point.
Re: Ideas for Logic to fill out this form
by borisz (Canon) on Jun 28, 2004 at 22:51 UTC
Re: Ideas for Logic to fill out this form
by clscott (Friar) on Jun 29, 2004 at 15:35 UTC

    If that's the behaviour that you want, you will have to preload all of the data into javascript arrays as you are creating the page and then write javascript to modify the drop down (select) menus.

    A google search for "select javascript depend" should turn up some useful tutorials like this one from Matt Kruse

    --
    Clayton
      Thanks for the advice and the links. Much appreciated.