PDA

View Full Version : Perl form problem with drop down menu


Anarchist
07-16-2005, 01:29 AM
I am trying to use a drop down box in my Perl form, the box should get its contents the list of data from a table in my database, how is this done?

At the moment I am stuck using the entire amount of data in my script which is ugly, I know there is a way to populate my box with the data but I cannot get my head around it.

Anyone know how?

This is what I am trying to escape from, I want the options filled dynamically from the table in the DB.


#!Perl

#output web page

print <<PAGE;

<html>
<head>

</head>
<body>

<FORM METHOD="GET" ACTION="dbooking.htm">
<form name="jump">
<select name="menu">
<option value="">London</option>
<option value="">Cardiff</option>
<option value="">Liverpool</option>
<option value="">Swansea</option>
<option value="">Newcastle</option>
<option value="">Middlesbrough</option>
<option value="">Manchester</option>
<option value="">Wigan</option>
<option value="">Wolverhampton</option>
<option value="">Edinburgh</option>
</select>


<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</div>
</body>
</html>
PAGE
exit 0;
#end script processing

rwedge
07-16-2005, 02:28 AM
You could use a foreach loop:use strict;
my @options = ('London','Cardiff','Liverpool','Swansea','Mewcastle','Middlesbrough',
'Manchester','Wigan','Wolverhampton','Edinburgh');
print <<PAGE;
<html>
<head>
</head>
<body>
<FORM METHOD="GET" ACTION="dbooking.htm">
<form name="jump">
<select name="menu">
PAGE

foreach my $options (@options) {
print "<option value=\"$options\">$options</option>\n";
}

print <<PAGE;
</select>
<INPUT TYPE="submit" VALUE="Submit">
</FORM>
</div>
</body>
</html>
PAGE
exit 0;
#end script processing

mlseim
07-16-2005, 05:03 AM
the box should get its contents the list of data from a table in my database

We almost need to see some of your actual database to know how you're storing your variables.