Drop down menu help

I'm trying to make a cgi page that has 2 dropdown menus: The first one is here already (using entry1 and entry2. I want a second dropdown menu that queries my database (the table names are entry1 and entry2, grabs the columns from the database, puts them in a second drop-down menu. When this second one is created, I wish for the user to be able to select one and then have it grab the data sorted by that category. I know the sql statements, but I'm trying to get to that point.

#!/usr/bin/perl -w
use CGI qw(:standard);
use DBI;
$q=new CGI;

start_html('New User Page');
print '<B>Please select the table from the drop down menu.</B><BR><BR>';

my $data_source="dbi:mysql:milesg";
my $user="milesg";
my $password="milesg";

print "<select name=\"tableName\">";
print "<option value=". "entry1" ."> "."entry1";
my @array=$sth->fetchrow_array;
print "<option value=". "entry2" ."> "."entry2"." </select>";


Who is Participating?
ok, got it. Just to summarize:
  you have 2 tables, entry1 and entry2
  both tables have different columns
  you want to have the columns been displayed in the second select which belong to the table selected in first select

I'd use CSS to do that:
  write both select tags with their option tags which contain the options
  give the select tag a id like_
   <select id=cols1> .... </select>
   <select id=cols2> .... </select>

in CSS you define:

#cols1 { display: visible; }
#cols2 { display: none; }

No you either write a JavaScript which toggles the display style from visible to none and vice versa
or you send the selection of the table to your server which returns a page with the toggled styles
confusing ...
you still have the first select, what's your problem writing the second select?
sousufferAuthor Commented:
the first drop down menu is using string entries by me

print "<select name=\"tableName\">";
print "<option value=". "entry1" ."> "."entry1";
my @array=$sth->fetchrow_array;
print "<option value=". "entry2" ."> "."entry2"." </select>";

i need to write something in javascript (in the cgi) that goes into the db and gets the table names
(something like this, but this doesn't work):

my $dbh=DBI->connect($data_source, $user, $password) or die "error";
my $sth=$dbh->prepare("show columns from entry1");
my $rc=$sth->execute;
my @array=$sth->fetchrow_array;

print "<select name=\"tableTwo\">";
print "<option value=". "$array[0]" ."> "."$array[0]";
my @array=$sth->fetchrow_array;
print "<option value=". "$array

this gets ONLY the columns from entry1 (as the db select statement shows)
If I changed the drop down menu (from the first drop down menu) selection to entry2, I want the second drop down menu to change the options in it.

So, drop down 1 has entry1, which has columns day, month, year while entry2 has serial_number, warranty_number, etc. When I change the first drop down menu to entry2, I want the second menu (drop down menu 2) to change the search options from day, month, and year to serial_number, etc. so I can then search by that.

The other problem I was having is that my second drop-down menu isn't displaying either, and I was looking for the problem with it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.