Welcome to WebmasterWorld Guest from 54.226.62.251

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

Reading a file

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

     

jaggudada

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

10+ Year Member



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

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

10+ Year Member



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.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month