?
Solved

Drop down menu help

Posted on 2005-04-12
6
Medium Priority
?
177 Views
Last Modified: 2013-12-25
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;

print
header('text/html'),
start_html('New User Page');
print '<B>Please select the table from the drop down menu.</B><BR><BR>';
print
$q->start_form(-method=>'POST',
-action=>'query.cgi',
-enctype=>'application/x-www-form-urlencoded'),

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>";

$q->endform,

end_html;
0
Comment
Question by:sousuffer
  • 2
3 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 13766367
confusing ...
you still have the first select, what's your problem writing the second select?
0
 

Author Comment

by:sousuffer
ID: 13766447
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.
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 1320 total points
ID: 13766572
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
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I have been answering a lot of questions like this in IT forums that I frequent. The question posed is usually something along the lines of "We have software X installed and need to uninstall it for reason Y" or some other variant of the sa…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question