CGI popup_menu -values=> iss variable possible?

Discussion in 'Perl Misc' started by John, Apr 13, 2006.

  1. John

    John Guest

    Hi

    I've got a variable $v:

    $v="['apple','banana','cherry']";

    print popup_menu (-name=>'fruit', -values=>$v);

    I've tried several permutations but cannot get it to work.

    It works if I insert the values into the popup_menu construct directly, but
    I do need to be able to use a variable.

    Any ideas?

    Regards
    John
    John, Apr 13, 2006
    #1
    1. Advertising

  2. John

    Paul Lalli Guest

    John wrote:
    > Hi
    >
    > I've got a variable $v:
    >
    > $v="['apple','banana','cherry']";


    This is a string, containing a left bracket, a single quote, the word
    apple, a quote, a comma, a quote, etc etc etc.

    You probably meant to have that variabe $v actually be an array
    reference, which would be:
    $v = ['apple', 'banana', 'cherry'];

    > print popup_menu (-name=>'fruit', -values=>$v);
    >
    > I've tried several permutations but cannot get it to work.
    >
    > It works if I insert the values into the popup_menu construct directly, but
    > I do need to be able to use a variable.


    I'm betting that when you "inserted teh values into the popup_menu
    construct directly", you did not erroneously insert extraneous
    double-quote characters.

    > Any ideas?


    If you don't understand what the [ ] are doing, you need to read up on
    references:
    perldoc perlreftut
    perldoc perllol

    Paul Lalli
    Paul Lalli, Apr 13, 2006
    #2
    1. Advertising

  3. John

    Todd Guest

    Did you try reading the manual? Mr. Stein has done a good job of
    documenting the module. Al

    Todd


    http://search.cpan.org/dist/CGI.pm/CGI.pm

    <snip>
    CREATING A POPUP MENU

    print popup_menu('menu_name',
    ['eenie','meenie','minie'],
    'meenie');

    -or-

    %labels = ('eenie'=>'your first choice',
    'meenie'=>'your second choice',
    'minie'=>'your third choice');
    %attributes = ('eenie'=>{'class'=>'class of first choice'});
    print popup_menu('menu_name',
    ['eenie','meenie','minie'],
    'meenie',\%labels,\%attributes);

    -or (named parameter style)-

    print popup_menu(-name=>'menu_name',
    -values=>['eenie','meenie','minie'],
    -default=>'meenie',
    -labels=>\%labels,
    -attributes=>\%attributes);

    popup_menu() creates a menu.

    1. The required first argument is the menu's name (-name).
    2. The required second argument (-values) is an array reference
    containing the list of menu items in the menu. You can pass the method
    an anonymous array, as shown in the example, or a reference to a named
    array, such as "\@foo".
    3. The optional third parameter (-default) is the name of the
    default menu choice. If not specified, the first item will be the
    default. The values of the previous choice will be maintained across
    queries.
    4. The optional fourth parameter (-labels) is provided for people
    who want to use different values for the user-visible label inside the
    popup menu and the value returned to your script. It's a pointer to an
    associative array relating menu values to user-visible labels. If you
    leave this parameter blank, the menu values will be displayed by
    default. (You can also leave a label undefined if you want to).
    5. The optional fifth parameter (-attributes) is provided to assign
    any of the common HTML attributes to an individual menu item. It's a
    pointer to an associative array relating menu values to another
    associative array with the attribute's name as the key and the
    attribute's value as the value.

    When the form is processed, the selected value of the popup menu can be
    retrieved using:

    $popup_menu_value = param('menu_name');

    </snip>

    John wrote:
    > Hi
    >
    > I've got a variable $v:
    >
    > $v="['apple','banana','cherry']";
    >
    > print popup_menu (-name=>'fruit', -values=>$v);
    >
    > I've tried several permutations but cannot get it to work.
    >
    > It works if I insert the values into the popup_menu construct directly, but
    > I do need to be able to use a variable.
    >
    > Any ideas?
    >
    > Regards
    > John
    >
    >
    >
    Todd, Apr 13, 2006
    #3
  4. John

    Paul Lalli Guest

    Todd wrote:
    > Did you try reading the manual?


    Did you try reading the original question? The OP is following the
    syntax of the popup_menu method perfectly. It is the creation of the
    array reference that's throwing him.

    Paul Lalli
    Paul Lalli, Apr 13, 2006
    #4
  5. John

    John Guest

    "Paul Lalli" <> wrote in message
    news:...
    > Todd wrote:
    >> Did you try reading the manual?

    >
    > Did you try reading the original question? The OP is following the
    > syntax of the popup_menu method perfectly. It is the creation of the
    > array reference that's throwing him.
    >
    > Paul Lalli
    >


    Hi.

    Many thanks. I've got a copy of it in front of me - somewhat tattered with
    use - well, at least the http://stein.cshl.org one.
    I can see it now. I need an array for the values and a hash array for he
    labels. At first sight, it looked like a string and that had thrown me.
    Armed with that I can now move a llittle further.

    Regards
    John
    John, Apr 13, 2006
    #5
  6. John

    robic0 Guest

    On Thu, 13 Apr 2006 19:18:54 +0100, "John" <> wrote:

    >
    >"Paul Lalli" <> wrote in message
    >news:...
    >> Todd wrote:
    >>> Did you try reading the manual?

    >>
    >> Did you try reading the original question? The OP is following the
    >> syntax of the popup_menu method perfectly. It is the creation of the
    >> array reference that's throwing him.
    >>
    >> Paul Lalli
    >>

    >
    >Hi.
    >
    >Many thanks. I've got a copy of it in front of me - somewhat tattered with
    >use - well, at least the http://stein.cshl.org one.
    >I can see it now. I need an array for the values and a hash array for he
    >labels. At first sight, it looked like a string and that had thrown me.
    >Armed with that I can now move a llittle further.
    >
    >Regards
    >John
    >

    What is cgi, and why should I care?
    robic0, Apr 14, 2006
    #6
  7. John

    robic0 Guest

    On Thu, 13 Apr 2006 19:21:36 -0700, robic0 wrote:

    >On Thu, 13 Apr 2006 19:18:54 +0100, "John" <> wrote:
    >
    >>
    >>"Paul Lalli" <> wrote in message
    >>news:...
    >>> Todd wrote:
    >>>> Did you try reading the manual?
    >>>
    >>> Did you try reading the original question? The OP is following the
    >>> syntax of the popup_menu method perfectly. It is the creation of the
    >>> array reference that's throwing him.
    >>>
    >>> Paul Lalli
    >>>

    >>
    >>Hi.
    >>
    >>Many thanks. I've got a copy of it in front of me - somewhat tattered with
    >>use - well, at least the http://stein.cshl.org one.
    >>I can see it now. I need an array for the values and a hash array for he
    >>labels. At first sight, it looked like a string and that had thrown me.
    >>Armed with that I can now move a llittle further.
    >>
    >>Regards
    >>John
    >>

    >What is cgi, and why should I care?


    I mean if you write perl code to import dbi material that you hardcode
    into an dynamic html stream that is not generated by a compliant writer,
    if it fails does anybody know it?
    robic0, Apr 14, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest

    Hi iss 6 is better than iss 5

    Guest, Mar 11, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    343
    Scott M.
    Mar 11, 2007
  2. Eric Schwartz
    Replies:
    0
    Views:
    110
    Eric Schwartz
    Dec 2, 2003
  3. Mallory Cloutier
    Replies:
    1
    Views:
    86
    Mallory Cloutier
    Aug 26, 2008
  4. Emil Tarazi

    CGI.pm popup_menu questions

    Emil Tarazi, Jun 7, 2004, in forum: Perl Misc
    Replies:
    1
    Views:
    159
    Brian McCauley
    Jun 7, 2004
  5. inetquestion

    cgi.pm popup_menu define select width?

    inetquestion, Mar 27, 2005, in forum: Perl Misc
    Replies:
    6
    Views:
    183
    Alan J. Flavell
    Mar 29, 2005
Loading...

Share This Page