Link to home
Start Free TrialLog in
Avatar of she2
she2

asked on

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?
Avatar of lambda
lambda

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'}";
Sorry, the first line shld read,

if ($ENV{'REQUEST_METHOD'} =~ /POST/i)
Actually the above correction wasn't necessary. I tried it only after I posted it !
ASKER CERTIFIED SOLUTION
Avatar of Paul Maker
Paul Maker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the same method is used to get values from all form input contols
Avatar of she2

ASKER

makerp:

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

@values = $query->param('selection1');