Forum Moderators: coopster & phranque

Message Too Old, No Replies

Multiple Selections in Drop Down List Boxes

         

Big_Perm

4:51 pm on Aug 1, 2001 (gmt 0)



From an HTML form where multiple selections are made in a list box, how can the data be processed for each selection?

sugarkane

7:04 pm on Aug 1, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Big_Perm (I love the username) - welcome to Webmasterworld.

In perl, using the CGI.pm module, you'd use something like

use CGI;
$query=CGI::new();
@values=$query->param("name_of_select");

This would put the multiple values into the array @values, and you can take it from there.

In PHP, I don't know - I'm assuming that the values will automatically be put into an array instead of a string, but I've never tried it. Anyone?

Brett_Tabke

8:48 am on Aug 2, 2001 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



(welcome to the board)

What language is going to receive the form values?

If perl, SugarKanes way will work, or this is an alternative:

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
if (length($buffer) < 3) {
$buffer = $ENV{QUERY_STRING};
}
@pairs = split(/&/, $buffer);

foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$name =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/\r//g;
$FORM{$name} = $value;

$o .="<br> Form name : <b>$name</b> Value : <b> $value </b>\n" if $debug>3;
}

Then all your form values are in %FORM{'name'}

Big_Perm

11:44 am on Aug 2, 2001 (gmt 0)



Actually i'm using VBScript. Can it be done in VBScript or possibly JavaScript? Thanks.

evinrude

4:55 pm on Aug 2, 2001 (gmt 0)

10+ Year Member



A quick example in asp:

Incoming form field name is "test", it's a multi select box. Variable "item" is just a handy descriptive variable to hold the value.

<%
for each item in request.form("test")
response.write("My value is: " & item & "<br />")
next
%>