homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
Reading a file
Reading a file and displaying contents in a form with <select> tag
jaggudada




msg:436929
 2:12 pm on Aug 16, 2004 (gmt 0)

I need to read from a text file stored on the server and load a huge list of things into a form so the user can interactively select, add or remove lines from the list. I know how to modify a form if the options are hardcoded, but I can't get javascrip to read a file. Any idea how to use .cgi or php to load a file and display its lines in a form using the <select> tag?
Thanx,

Jaggudada

 

markanthony




msg:436930
 3:33 pm on Aug 16, 2004 (gmt 0)

With perl you could do something like this:
This will, ofcourse, depend on how your data is stored, I am assuming that it is in some sort of record format for this example. I have also assumed that you only have a single line of options delimited by tabs.

##############################perl code
#!/usr/bin/perl -w

use strict;
my @options;

open(FILEIN, ">thefileyouneed.txt");

while(<FILEIN>)
{
chomp; #removes the newline and/or CR
@options = split("\t", $_);
}

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

#the next line demonstrates 'here' document quoting...everything is interpolated and newlines etc ignored.
print <<"EOF";
<html>
<body>
<form>
<select>
EOF
while(@options)
{
my $option = shift;
print "<option name=" . $option . " value=" . $option . "\n";
}
print <<"EOF";
</select>
</form>
</body>
</html>
EOF

close(FILEIN);
##################################end perl.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved