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

Hello All:

I was wondering if the following scenario can be accomplished using Perl.

I have an HTML form. The beginning of the form is pretty basic: customer name, address, phone, etc.

The next section of the form asks the customer to select a machine category. There are three categories: A, B, C.

When a customer selects a machine category, in this case category A, I would like a pop up menu to appear listing all the machines that are in Category A. If someone selects category B, the pop up menu should appear with the machines only in category B.

After the customer selects the machine within a category, the customer can complete the rest of the form and submit the data.

My question: Is it possible to accomplish the pop up menu listing specific machines within a selected category (as mentioned above)?

If so, can someone point me in the right direction as to where to begin?

Thank you in advance for any assistance.

Replies are listed 'Best First'.
Re: HTML/Perl form question
by injunjoel (Priest) on Nov 09, 2004 at 19:08 UTC
    Greetings all,
    Here is an example of what we do when we need contingent dropdowns.
    <script language="JavaScript" type="text/javascript"> var comm_list = new Array(); comm_list[0] = new Array("first", 34, 37); comm_list[1] = new Array("second", 35, 37); comm_list[2] = new Array("third", 36, 37); comm_list[3] = new Array("primary", 42, 38); comm_list[4] = new Array("secondary", 43, 38); </script> <script language="JavaScript" type="text/javascript"> function change_dd(parent, target, list){ var f = parent.form; var value = parent.options[parent.options.selectedIndex].value +; f.elements[target].options.length = 0; if(value == "0"){ var newopt = new Option('--- Select an Option ---', '0'); f.elements[target].options[f.element[target].options.lengt +h] = newopt; }else{ for(var i = 0; i < list.length; i++){ if(list[i][2] == value){ var newopt = new Option(list[i][0], list[i][1]); f.elements[target].options[f.elements[target].opti +ons.length] = newopt; } } } } </script>
    And here is the call from your the controlling dropdown in this case it would be your categories.
    <select name="selection" onChange="change_dd(this, 'other_dd', comm_li +st)"> <option value="0">--- Select a Type ---</option> <option value="38">positional</option> <option value="37">numeric</option> </select> <select name="other_dd"> </select>
    A little explaination is in order eh?
    the "selection" dropdown calls the function change_dd and sends it itself, the other dropdown to populate as well as which list to use to do the population of the dropdown. So you will need the other dropdown set up for the population to take place.
    The list "comm_list" is created based on the selections available in the "selection" dropdown and contain in this order: the text to display, the value to pass, the parent id for the association.
    Let me know if you have any questions.

    -InjunJoel

    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
Re: HTML/Perl form question
by wfsp (Abbot) on Nov 09, 2004 at 18:57 UTC
    Not directly. The data would need to be within the form so it is really a question of HTML/javascript.

    Perl could construct the page, including the form. CGI.pm discusses how you might do this.

    You could also consider HTML::Template.

    I would get the form working first, though, and then use either of the above to implement it. This would save having data hard coded into a static HTML page, which, I presume, you would rather avoid.

Re: HTML/Perl form question
by pg (Canon) on Nov 09, 2004 at 18:47 UTC

    Yes, two folds: (1)perl can create the dropdown list for you; (2) Something like JavaScript is a fit to control the logic between two dropdown lists. (When I said "two dropdown lists", I assumed that there was a dropdown list containing catogories: 'A', 'B', 'C'. But it could be just a group of radio buttons. That's your choice.)

      Thank you for the info. I'll look into JavaScript.

        If you create JavaScript solutions, please think of <noscript> sections for non-JS enabled browsers. If your audience is well known (like say, an intranet with identical browsers and setups people can't change) go ahead. If there's a possibillity of people not using JavaScript, please think of a backup plan for them.

        --
        b10m "JavaScript is Evil!"

        All code is usually tested, but rarely trusted.