Solved

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

Posted on 2000-03-19
7
220 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?
0
Comment
Question by:she2
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:lambda
ID: 2635268
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
 
LVL 1

Expert Comment

by:lambda
ID: 2635272
Sorry, the first line shld read,

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

Expert Comment

by:lambda
ID: 2635311
Actually the above correction wasn't necessary. I tried it only after I posted it !
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Accepted Solution

by:
makerp earned 50 total points
ID: 2635363
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
 
LVL 10

Expert Comment

by:makerp
ID: 2635366
the same method is used to get values from all form input contols
0
 

Author Comment

by:she2
ID: 2636539
makerp:

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

Expert Comment

by:lambda
ID: 2638809

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

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Filtering a file to table 9 102
add a syntax to a csv file 8 99
Regular Expression question to filter with negation. 6 104
Perl Untar File 1 68
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question