CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Multiple Options in a drop down box

 



PeterLove
Deleted

Jun 13, 2000, 11:14 AM

Post #1 of 1 (397 views)
Multiple Options in a drop down box Can't Post

My problem is that I can print my options from a file but I can only print 1 option, even
if I made more than one option for that product.

Here is my options file:
1001:5:Red +$12.00:12.00
1002:1:Green +$2.50:2.50
1002:7:Blue +10.99:10.99
1002:3:Orange +$3.50:3.50

It works like this:
productid ptionid:desctiption:price


Here I take the options and put it into a hash:

sub get_options {
open(OPTIONS, "options");
while(<OPTIONS> ) {
chomp($_);
@option = split(/:/, $_, 4);
$options{$option[0]} = join(":", @option);
}
close(OPTIONS);
return (%options);
}

In another cgi file I wrote this:
%options = &get_options(%options);

...

foreach $option_string (values %options) {
@option = split(/:/, $option_string, 4);
if($prod[0] eq $option[0] &#0124; &#0124; $prod[0] == $option[0]) {
&print_options(\@prod, \@option);
...

This takes the options hash and if there is an option for that product it will print it go to print_options.

Print Options is:

sub print_options {
my($what) = shift;
my($option) = shift;
if($option->[0] eq $what->[0] &#0124; &#0124; $option->[0] == $what->[0]) {

print "<td><FONT SIZE=\"2\"></FORM><FORM name=\"options\"><SELECT NAME=\"\">";
print "<OPTION SELECTED VALUE=\"NONE\">Select</OPTION>";
foreach $result ($option->[2]) {
print qq|<Option value="$result"> $result</OPTION>\n|;
}
print "</SELECT></td>";
}
}

Then I just call it from print_products:

...
my($what) = shift;
my($option) = shift;

if($option->[0] eq $what->[0] &#0124; &#0124; $option->[0] == $what->[0]) {
unless($option->[2] eq "" &#0124; &#0124; $option->[2] eq " " &#0124; &#0124; $option->[2] eq "" &#0124; &#0124; $option->[2] == " ") {
&print_options;
}
}
...

With this if there is an option for that product it will make a drop down box and add only 1 option, even if
I wrote more than one option for it.

How could I go around fixing this? For I can have more than one option for a product.

Thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives