We help IT Professionals succeed at work.

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

she2
she2 asked
on
256 Views
Last Modified: 2010-03-05
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?
Comment
Watch Question

Commented:
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'}";

Commented:
Sorry, the first line shld read,

if ($ENV{'REQUEST_METHOD'} =~ /POST/i)

Commented:
Actually the above correction wasn't necessary. I tried it only after I posted it !
CERTIFIED EXPERT
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT

Commented:
the same method is used to get values from all form input contols

Author

Commented:
makerp:

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

Commented:

@values = $query->param('selection1');
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.