Solved

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

Posted on 2000-03-19
7
218 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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 …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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