Solved

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

Posted on 2000-03-19
7
216 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now