Construct listbox with CGI

S

sam

Hi,

I need to use CGI to construct a listbox.
I m currently using OO style of CGI.
Does anyone got an example how to use CGI to build a listbox?
I need to submit the values in the listbox to another CGI form, that's
why I need the listbox to be constructed by CGI.

Thanks
Sam
 
S

sam

sam said:
Hi,

I need to use CGI to construct a listbox.
I m currently using OO style of CGI.
Does anyone got an example how to use CGI to build a listbox?
I need to submit the values in the listbox to another CGI form, that's
why I need the listbox to be constructed by CGI.

Thanks
Sam
I found it by looking up the CGI.pm file. It's name is scrolling_list if
I m correct.

Sam.
 
S

sam

sam said:
Hi,

I need to use CGI to construct a listbox.
I m currently using OO style of CGI.
Does anyone got an example how to use CGI to build a listbox?
I need to submit the values in the listbox to another CGI form, that's
why I need the listbox to be constructed by CGI.
Hi,

I have written the following CGI code, but the listbox does not insert
data to the listbox. These data is retrieved from the MySQL datasbase:

my $values = "";
my $lables = "";
while ($aref = $sth->fetchrow_arrayref){
$values .= $aref->[0].",";
$labels .= $aref->[0]." => " .
$aref->[1].":".$aref->[2].",";
}

print $query->scrolling_list(
-NAME => "Examples",
-VALUES => [ qw($values) ],
-LABELS => {$labels},

-SIZE => 3,
-MULTIPLE => 1, # 1 for true, 0 for false
);

When I execute this code, the listbox is inserted with the string
"$values" in the box instead of the values in the $values variable.

What s wrong with this code?

Thanks
Sam
 
S

sam

sam said:
sam said:
Hi,

I need to use CGI to construct a listbox.
I m currently using OO style of CGI.
Does anyone got an example how to use CGI to build a listbox?
I need to submit the values in the listbox to another CGI form, that's
why I need the listbox to be constructed by CGI.
Hi,

I have written the following CGI code, but the listbox does not insert
data to the listbox. These data is retrieved from the MySQL datasbase:

my $values = "";
my $lables = "";
while ($aref = $sth->fetchrow_arrayref){
$values .= $aref->[0].",";
$labels .= $aref->[0]." => " .
$aref->[1].":".$aref->[2].",";
}

print $query->scrolling_list(
-NAME => "Examples",
-VALUES => [ qw($values) ],
-LABELS => {$labels},

-SIZE => 3,
-MULTIPLE => 1, # 1 for true, 0 for false
);

When I execute this code, the listbox is inserted with the string
"$values" in the box instead of the values in the $values variable.

What s wrong with this code?
Hi,

I have changed the above code to the following, it nearly working as I
expected:
my @values;
my @lables;
my $i;
for ($i=0; $aref = $sth->fetchrow_arrayref; $i++){
$values[$i] = $aref->[0]; #custcode
$labels[$i] = $aref->[1]; #custname
}

print $query->scrolling_list(
-NAME => "Outlets",
-VALUES => [@values],
-LABELS => \%labels,
-SIZE => 9,
-MULTIPLE => 1,
);

However it inserted custcode to the listbox. I m expecting custnames on
the "label=" side of the listbox, and custcode is on the "value=" side
of the listbox.

How can I fix this error?
 
P

Paul Lalli

You have an extremely annoying tendency of replying to yourself over and
over in this group. This implies (at least to me) that you default to
asking thousands of people for help, and *then* attempt to do the work
on your own. Please consider swapping the priority of these methods.

Also, please read the posting guidelines for this group. Specifically,
stop quoting the fulltext of every message you reply to. Trim the
quotes to only what is relevant to your reply. Further, you should be
posting *short* but *complete* scripts when you ask for help - including
use strict; and use warnings;

my @values;
my @lables;
my $i;
for ($i=0; $aref = $sth->fetchrow_arrayref; $i++){
$values[$i] = $aref->[0]; #custcode
$labels[$i] = $aref->[1]; #custname
}

print $query->scrolling_list(
-NAME => "Outlets",
-VALUES => [@values],
-LABELS => \%labels,
-SIZE => 9,
-MULTIPLE => 1,
);

However it inserted custcode to the listbox. I m expecting custnames on
the "label=" side of the listbox, and custcode is on the "value=" side
of the listbox.

How can I fix this error?

You define an array called @labels, you assign to that array, and then
you attempt to create your scrolling_list with the non existent hash
variable %labels. You need to re-read the documentation for CGI.pm to
understand what %labels is supposed to contain.

If you had run this script under use strict; it would have warned you
that %labels doesn't exist. Please don't ask thousands of people to do
the work of a computer for you.

Paul Lalli
 
S

sam

You define an array called @labels, you assign to that array, and then
you attempt to create your scrolling_list with the non existent hash
variable %labels. You need to re-read the documentation for CGI.pm to
understand what %labels is supposed to contain.

If you had run this script under use strict; it would have warned you
that %labels doesn't exist. Please don't ask thousands of people to do
the work of a computer for you.
Thanks for the hints, I was just trying to be more descriptive so that
others understand my question.

Sorry again if that annoyed you.
Thanks for your help
Sam.
 
I

ioneabu

I have changed the above code to the following, it nearly working as I
expected:
my @values;
my @lables;
my $i;
for ($i=0; $aref = $sth->fetchrow_arrayref; $i++){
$values[$i] = $aref->[0]; #custcode
$labels[$i] = $aref->[1]; #custname
}

print $query->scrolling_list(
-NAME => "Outlets",
-VALUES => [@values],
-LABELS => \%labels,
-SIZE => 9,
-MULTIPLE => 1,
);

However it inserted custcode to the listbox. I m expecting custnames on
the "label=" side of the listbox, and custcode is on the "value=" side
of the listbox.

How can I fix this error?
Thanks
Sam

True that %labels does not exist. Since you are giving what resolves
to -LABELS=>undef, CGI.pm intelligently uses what you passed to -VALUES
for values and labels. I learned very recently that a hash slice can
be used to make the %labels hash that you need.

@labels{@values} = @labels;

Keep in mind that the @ at the beginning lets Perl know you are doing a
hash slice. The first @labels refers to the %labels hash and the
second @labels refers to the @labels array. This is one place where
using the same name for two different type variables might get
confusing.

wana (hope I explained it right)
 
I

ioneabu

I wrote

@labels{@values} = @labels

and groups.google.com turned it into:

@labe...@values} = @labels;
I checked it before posting. I don't know what happened.

wana
 
I

ioneabu

It did it again. Very strange. Is it only google.groups that displays
it wrong? Or, is it my browser?

Sorry to answer myself twice here, but what I am typing is not being
displayed properly.

my ls{ is being turned to ...


wana
 
P

Paul Lalli

It did it again. Very strange. Is it only google.groups that displays
it wrong? Or, is it my browser?

Sorry to answer myself twice here, but what I am typing is not being
displayed properly.

my ls{ is being turned to ...

It would seem to be a problem with Google Groups' rendering. I see the
issue you refer to in both FireFox and IE at Google Groups, but my
default news reader shows your messages as you actually typed them.

Paul Lalli
 
J

Joe Smith

http://groups-beta.google.com/group/comp.lang.perl.misc/msg/66eb83d49e4cee78?dmode=source

(e-mail address removed) commented:
I wrote

@labels{@values} = @labels

and groups.google.com turned it into:

@labe...@values} = @labels;
I checked it before posting. I don't know what happened.

There are three other instances of this corruption in Google's
display of your posting:

From: (e-mail address removed)
X-Complaints-To: (e-mail address removed)
Complaints-To: (e-mail address removed)

In other words:
($text_to_display = $original_text) =~ s/(\w+)\w{3}\@/$1...\@/g;

Attempting to change '(e-mail address removed)' to '(e-mail address removed)'
is the wrong thing to do in this case.

-Joe
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top