Allen Allen - 1 year ago 76
HTML Question

Perl ReadParse to process SELECT html tag with multiple options slected

How do I access all the options selected from a SELECT tag which is then passed into a form using POST
The HTML form is setup like this:

<div class="header">
<h6>Hold Down control(CTRL) key to select multiple CMSs</h6>

<SELECT NAME = "cms" multiple>

<option>#1 - 15 N 0.4 N/O ONTARIO AVE</option>>
<option>#2 - 15 S 1.1 S/O 6TH</option>>
<option>#3 - 215 N CENTRAL 215</option>>
<option>#4 - 215 S 0.45 S/O IOWA</option>>

<INPUT TYPE=SUBMIT VALUE="Submit Form" align="center">


The Perl portion where it handles the POST data using ReadParse:

use CGI qw(:cgi-lib :standard);

$cms = $in{"cms"};

Displaying the content of
just shows the first option selected despite multiple selection. How do I access the passed in data?

Answer Source
use CGI qw(:cgi-lib :standard);

Aaaah, the nineties...

How do I access all the options selected from a SELECT tag?

Use multi_param:

my @v = multi_param('cms');

In doing so, you'll be giving up compatibility with Perl 4's That is, don't use &ReadParse(%in); Instead, access values of CGI parameters using param and ditch the %in hash.

According to perldoc perlhist, last version of Perl 4 was released in 1993:

Larry 4.036 1993-Feb-05 Very stable.

You may be stuck with an older version of It was added in 2014. If that is the case, you can use my @v = param('cms'); but do read the documentation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download