Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Construct listbox with CGI

Reply
Thread Tools

Construct listbox with CGI

 
 
sam
Guest
Posts: n/a
 
      12-30-2004
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
 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      12-30-2004
sam wrote:

> 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.
 
Reply With Quote
 
 
 
 
sam
Guest
Posts: n/a
 
      12-30-2004
sam wrote:

> 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
 
Reply With Quote
 
sam
Guest
Posts: n/a
 
      12-30-2004
sam wrote:

> sam wrote:
>
>> 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?
> Thanks
> Sam

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-30-2004
"sam" <> wrote in message
news:cr0rbm$1cm2$...

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

 
Reply With Quote
 
sam
Guest
Posts: n/a
 
      12-30-2004
Paul Lalli wrote:

> "sam" <> wrote in message
> news:cr0rbm$1cm2$...
>


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

> Paul Lalli
>

 
Reply With Quote
 
ioneabu@yahoo.com
Guest
Posts: n/a
 
      12-30-2004

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

 
Reply With Quote
 
ioneabu@yahoo.com
Guest
Posts: n/a
 
      12-30-2004
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

 
Reply With Quote
 
ioneabu@yahoo.com
Guest
Posts: n/a
 
      12-30-2004
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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-30-2004
<> wrote in message
news: oups.com...
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Behavior of if construct in switch case defualt construct. Mukesh C Programming 4 03-26-2010 12:38 PM
Listbox item added with client scripts not submitting with ASP:Listbox Simon Prince ASP .Net 2 10-19-2004 04:11 PM
How do I move all items in a listbox to another listbox kent ASP .Net 1 05-03-2004 12:17 AM
click listbox and refresh another listbox DC Gringo ASP .Net 0 04-06-2004 02:13 AM
Re: now desparate! - 1st listbox contents disappears when 2nd listbox appears? blenderdude ASP .Net 0 08-03-2003 10:18 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57