in mutiple selection list, how to get the selected item?

in the Html, I use  mutiple selection list, how to get the selected item?

in the cgi(or Pl) , how to get the selected item?
she2Asked:
Who is Participating?
 
makerpCommented:
use cgi.pm

i.e.

# the module
use CGI;
# create a cgi object
$query = new CGI;
# use the param methos of our cgi object to obatin a variable passed from our calling form
print("my selection was : ".$query->param('selection1'));

cgi.pm contains a whole host of methods to do the cgi donkey work for you. cpan or activestate have it for download. every body uses it. you dont need to worry about decoding querysrings etc with it.
0
 
lambdaCommented:
In Perl, the selected value will be passed along with the query string. U just have to decode the query string & get the value.

If ur select box has name 'sel_list',

if ($ENV{REQUEST_METHOD} =~ /POST/i)
{
   read(STDIN, $cache, $ENV{'CONTENT_LENGTH'});
}
else
{
  $cache = $ENV{'QUERY_STRING'};
}

   @pairs = split(/&/, $cache);
   foreach $pair (@pairs) {
      ($name, $value) = split(/=/, $pair);

      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

      $FORM{$name} = $value;
   }

print "the selected value is $FORM{'sel_list'}";
0
 
lambdaCommented:
Sorry, the first line shld read,

if ($ENV{'REQUEST_METHOD'} =~ /POST/i)
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
lambdaCommented:
Actually the above correction wasn't necessary. I tried it only after I posted it !
0
 
makerpCommented:
the same method is used to get values from all form input contols
0
 
she2Author Commented:
makerp:

thanks!, but $query->param('selection1')
should be arry of string, how to set up the array of string, and how to access?
0
 
lambdaCommented:

@values = $query->param('selection1');
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.