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

Hi all,
I have a problem.
Im developing a web page using perl script.
I have two combo(popup list) boxes.
If I select any one value(item) from first list, the items in the second list should be filled depending on the item selected in the first list.
I have to retrieve values for second list from a remote database.(database connection & access everything is ok).
Only thing is that im unable to get the logic how to load a list when another list item is seleted.
Anyone pls. help me.
Thank you in advance.

Replies are listed 'Best First'.
Re: Populating Popup Lists
by Corion (Patriarch) on Apr 27, 2004 at 11:04 UTC

    There are two approaches to your problem, one completely unrelated to Perl and one marginally related to Perl:

    If you want to send a database query after some item has been selected without reloading the whole page, you will have to look at how Orkut (for example) does this with the XMLHTTPRequest object. This is a possibly convenient way of doing things, but it locks out all people who have disabled JavaScript and all people not using a recent browser, as there is no implicit graceful fallback.

    If you can instead load the whole data in one go and only later update the contents of the popup list based on the selection in another list, then creating that page is easily done with Perl and one of the templating modules. The problem remains how to change the contents of the popup list. Google gives this link, possibly you will find better links by using Google yourself.

Re: Populating Popup Lists
by bradcathey (Prior) on Apr 27, 2004 at 11:19 UTC
    Previous posters are correct, this is typically a javascript task, which, as a web guy, I do all the time. However, in a recent project I am doing almost exactly what you decribe--one where user selections progressively narrow their options. My method is to have the user "Go" after selecting from the first set of options, which submits the form to my Perl script. The script uses the choice to tap the MySQL db and build the second set of choices and populate the next dropdown. This repeats a couple of more times. I do it all with HTML::Template, a wonderful module that is easy to use and perfect for this kind of thing--especially for those wanting to avoid javascript (not really my reason, but it's actually easier using Perl and H::T. Read up on HTML::Template in Tutorials or CPAN. Good luck.

    —Brad
    "A little yeast leavens the whole dough."
Re: Populating Popup Lists
by Abigail-II (Bishop) on Apr 27, 2004 at 10:59 UTC
    That's not a Perl question, unless you are targetting browsers with some kind of Perl plugin, and you're writing client side Perl programs. What you want is that the browser takes some action, triggered by user input. I suggest consulting a Javascript resource.

    Abigail