List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:May 8 2000 12:31am
Subject:Re: Drop Down Menu with defined Data:
View as plain text  
I tried to clean up the code and below is my attempt at creating two drop
down menus with
the second drop down menu relating to the first, but somehow I don't think
I'm grabbing the value selected from the first drop down menu?  Is there an
easy way to do this?

Thanks

Douglas

#!/usr/bin/perl

use DBI;
use strict;
use CGI qw(:standard :html3 escape unescape escapeHTML);

my ($dns) = "DBI:mysql:labs:localhost";
my ($user_name) = " ";
my ($password) = " ";
my ($dbh, $sth);
my $college;
my $dept;
my (%attr) =
(
     PrintError => 0,
     RaiseErrir => 0
);

$dbh=DBI->connect($dns,  $user_name, $password, \%attr) or
bail_out ("Cannot Connect to database\n");


#-------------------------------------------------
#Begin HTML output
print $query->start_html (-title =>'Database
Test',-BGCOLOR=>'#000000',-vlink=>'#ffffff',-alink=>'#ffffff',
-link=>'#ffffff');


# print data to screen for user to see
print "<h2><center>Drop Down Menu Test";
print " Results:</h2></center></font></P>";
print "<center>";
#
my $method="";
my $action="";
$method="post";
$action="http://localhost/cgi-bin/test.pl";
#-------------------------------------------------

print $query->startform($method,$action);

##The first drop down menu
## "list"  will be the name of the table in the database.
print "Please Select your College";
my $sth = $dbh->prepare("select college from list")
$sth->execute;
my @arr=();
while (@arr = $sth->fetchrow_array())
{
($college)=@arr;
$college = $college;
print $query->popup_menu (-name=>'COLLEGE',
                         -"values"=>['$college',

],
-default=>$defaultcollege);
}
$sth->finish();

## second drop down menu
print "<BR>";
print "Please Select the Department</td><td>";
my $sth = $dbh->prepare("select dept from list
where college="$college" ")
$sth->execute;
my @arr=();
while (@arr = $sth->fetchrow_array())
{
($dept)=@arr;
$dept = $dept;
print $query->popup_menu (-name=>'DEPT',
                         -"values"=>['$dept',

],
-default=>$defaultdept);
}
print qq{<input type="submit" VALUE="Submit">};
print "</form></body></html>\n";

$sth->finish();
$dbh->disconnect ();
exit;

Thread
Drop Down Menu with defined Data:Douglas Brantz8 May
  • Re: Drop Down Menu with defined Data:Douglas Brantz8 May
    • RE: Drop Down Menu with defined Data:benjamin-weiss8 May
      • Re: Drop Down Menu with defined Data:Douglas Brantz8 May
        • Re: Drop Down Menu with defined Data:Christopher R. Jones8 May
        • RE: Drop Down Menu with defined Data:benjamin-weiss8 May