Construct listbox with CGI

Discussion in 'Perl Misc' started by sam, Dec 30, 2004.

  1. sam

    sam Guest

    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
    sam, Dec 30, 2004
    #1
    1. Advertising

  2. sam

    sam Guest

    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.
    sam, Dec 30, 2004
    #2
    1. Advertising

  3. sam

    sam Guest

    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
    sam, Dec 30, 2004
    #3
  4. sam

    sam Guest

    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
    sam, Dec 30, 2004
    #4
  5. sam

    Paul Lalli Guest

    "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
    Paul Lalli, Dec 30, 2004
    #5
  6. sam

    sam Guest

    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
    >
    sam, Dec 30, 2004
    #6
  7. sam

    Guest


    >
    > 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)
    , Dec 30, 2004
    #7
  8. sam

    Guest

    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
    , Dec 30, 2004
    #8
  9. sam

    Guest

    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
    , Dec 30, 2004
    #9
  10. sam

    Paul Lalli Guest

    <> wrote in message
    news:...
    > 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
    Paul Lalli, Dec 30, 2004
    #10
  11. sam

    Joe Smith Guest

    Re: Construct listbox with CGI [Answer mangled by groups-beta.google.com]

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

    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:
    X-Complaints-To:
    Complaints-To:

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

    Attempting to change '' to ''
    is the wrong thing to do in this case.

    -Joe
    Joe Smith, Dec 31, 2004
    #11
    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. blenderdude
    Replies:
    0
    Views:
    799
    blenderdude
    Aug 3, 2003
  2. DC Gringo
    Replies:
    0
    Views:
    393
    DC Gringo
    Apr 6, 2004
  3. kent
    Replies:
    1
    Views:
    866
    Andrew de la Harpe
    May 3, 2004
  4. Simon Prince
    Replies:
    2
    Views:
    3,312
    =?Utf-8?B?TWljaGFlbCBUYXlsb3I=?=
    Oct 19, 2004
  5. Mukesh
    Replies:
    4
    Views:
    606
    Paul N
    Mar 26, 2010
Loading...

Share This Page