Drop down menu help

Posted on 2005-04-12
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;

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


Question by:sousuffer
    LVL 51

    Expert Comment

    confusing ...
    you still have the first select, what's your problem writing the second select?

    Author Comment

    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.
    LVL 51

    Accepted Solution

    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

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
    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…
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    732 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now