CGI popup_menu -values=> iss variable possible?

J

John

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
 
P

Paul Lalli

John said:
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
 
T

Todd

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>
 
P

Paul Lalli

Todd said:
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
 
J

John

Paul Lalli said:
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
 
R

robic0

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?
 
R

robic0

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top