samurai_from_india has asked for the wisdom of the Perl Monks concerning the following question:

what i want is to get the multiple selected data from an html form .
<select name="list1" multiple> <option value=1>sunday</option> . . <option value=7>saturday</option> </select>
so if the user selects multiple value i want to get them how can i get them.

thanx

janitored by ybiC: <code> tags, slight shortening of title

Replies are listed 'Best First'.
Re: Get form data from select box, html forms, multiple selection
by Anonymous Monk on Nov 17, 2003 at 14:24 UTC
    use CGI 'param'; my @selections = param('list1');
Re: Get form data from select box, html forms, multiple selection
by bassplayer (Monsignor) on Nov 17, 2003 at 14:30 UTC
    Here's something to get you started:
    #!/usr/bin/perl use strict; use warnings; use CGI; # create new CGI object my $q = CGI->new(); # clean assignment of CGI parameters my %param = $q->Vars(); # $param{list1} contains selected fields separated # by null character \0 my @days_selected = split /\0/, $param{list1};
    The @days_selected array contains the data you desire.

    Unfortunately the example posted above by AM will only give you the first of the options selected.
    Update: Apologies, A, old boy. Thanks, L~R.

    bassplayer

      bassplayer,
      I believe you are mistaken concerning the AM. From the CGI docs:

      Pass the param() method a single argument to fetch the value of the named parameter. If the parameter is multivalued (e.g. from multiple selections in a scrolling list), you can ask to receive an array. Otherwise the method will return a single value.

      Using the Vars method to get all the params into a hash seems like a waste in this case.

      L~R