Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DROPDOWN LISTS FROM ARRAYS HELP

Status
Not open for further replies.

madaxe

Technical User
Dec 21, 2004
44
0
0
US
I want to creat a drop down menu from an array can anybody help, i think im on the right track but i cant get it to work. My code below.


Mad Axe


#!/Perl/bin/perl

use CGI;

$userlist = "playerlist.cgi";

print "Content-type: text/html\n\n";

open (PLAYERLIST, "$playerlist");
@userlist = <PLAYERLIST>;
close (PLAYERLIST);


<FORM ACTION='datahandling.cgi' METHOD=POST>
<SELECT NAME="TEST">

foreach $dataline (@userlist){
chomp $dataline;
($value, $description) = split(/\|/, $dataline);

<OPTION VALUE='$value'>$discription</OPTION>

}

</SELECT>
<INPUT TYPE=SUBMIT value="Tell Me">
</FORM>




ARRAY FILE playerlist.cgi



marc1|player1
marc2|player2
marc3|player3
marc4|player4
marc5|player5
marc6|player6
 
Code:
#!/Perl/bin/perl

use CGI;

$userlist = "playerlist.cgi";

print "Content-type: text/html\n\n";

open (PLAYERLIST, "$playerlist");
@userlist = <PLAYERLIST>;
close (PLAYERLIST);


print "<FORM ACTION='datahandling.cgi' METHOD=POST>
<SELECT NAME="TEST">\n";

    foreach $dataline (@userlist){
        chomp $dataline;
        ($value, $description) = split(/\|/, $dataline);
        print "<OPTION VALUE=\"$value\">$d[b]e[/b]scription</OPTION>\n";

}
print "</SELECT>\n";
print "<INPUT TYPE=SUBMIT value=\"Tell Me\">\n";
print "</FORM>";
Code:
ARRAY FILE  playerlist.cgi



marc1|player1
marc2|player2
marc3|player3
marc4|player4
marc5|player5
marc6|player6

You can syntax check your scripts on the command line using
Code:
perl -c myscript.pl

HTH
--Paul

cigless ...
 
Have a look at the documentation for CGI.pm at


To change the example to use an array, add 'scalar' ahead of scrolling list

scrolling_list(
-name=>'list_name',
-values=>['eenie','meenie','minie','moe'],
-default=>['eenie','moe'],
-size=>5,
-multiple=>'true',
-labels=>\%labels);

scalar scrolling_list(
-name=>'TEST',
-values=>[@userlist],
-default=>['eenie','moe'],
-size=>5,
-multiple=>'true',
-labels=>\%labels);

Also if value and description populated a hash called 'labels' the label tag shown would work.
 
Hi i tried the first piece of code and it would not work i kept getting the following server error:-

Premature end of script headers: dropdown4.cgi, referer:

Bareword found where operator expected at C:/Documents and Settings/mcjeeves/My Documents/My Website/RON/junk/dropdown4.cgi line 15, near "<SELECT NAME="TEST", referer:
(Might be a runaway multi-line "" string starting on line 14), referer:
\t(Missing operator before TEST?), referer:
String found where operator expected at C:/Documents and Settings/mcjeeves/My Documents/My Website/RON/junk/dropdown4.cgi line 15, near "TEST">\\n"", referer:
syntax error at C:/Documents and Settings/mcjeeves/My Documents/My Website/RON/junk/dropdown4.cgi line 15, near "<SELECT NAME="TEST", referer:
Execution of C:/Documents and Settings/mcjeeves/My Documents/My Website/RON/junk/dropdown4.cgi aborted due to compilation errors., referer:

ive only been writting perl for a week and this is a little confusing "perl -c myscript.pl" can you explain this in a bit more detail

Madaxe
 
The third post i also found a little confusing ive only just started so im a little green and frustrated how would this fit into my existing script and how would it pass the info to my next cgi using forms?


scalar scrolling_list(
-name=>'TEST',
-values=>[@userlist],
-default=>['eenie','moe'],
-size=>5,
-multiple=>'true',
-labels=>\%labels);


Mad axe
 
print "<FORM ACTION='datahandling.cgi' METHOD=POST>
<SELECT NAME=\"TEST\">\n";


cigless ...
 
Thanks for that i still have one problem my dropdown list does not contain anything im not sure if its reading the file correctly


MadAxe
 
DONT WORRY TYPO as follows

$userlist = "playerlist.cgi";

should be

$playerlist

Thanks For your help


Madaxe
 
ur welcome, happy new year
--Paul

cigless ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top