Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display content of a file from combobox

    What i wanted to do is to display all items(flat file) in a directory into a combobox.
    Den display the content in the flat file once the item is selected.
    I have problem implementing it. Pls advice and guide me.
    Thanks

    Code:
    print "Content-type: text/html\n\n";
    print "<html><head>";
    print "<title>Test</title>";
    print "<meta http-equiv=refresh content=600>";
    print "</head><body topmargin=5 rightmargin=5 leftmargin=30>";
    
    print "<form name=\"inputList\" action=\"\" method=\"post\">";
    
    print qq|Test Name: <input type="Text" name="testName">|;
    
    @testList = `ls -1 /u/cgi-bin/test/List`;
    
    #list content
    	print "<select name=\"testDropList\">";
    for(@testList){
    	$testName = $_;	
           	print "<option value=\"\">$testName</option>";
    }
    	print "</select>";
    
    $data_file="testDropList";
    
    
    print <<END;
    <center>
    <p>&nbsp;</p>
    <p><font class=footer>
    </font><p>
    </center>
    </body></html>
    END
    
    open(DAT, $data_file) || die("Could not open file!"); 
    @raw_data=<DAT>; 
    close(DAT); 
    
    #display content
    foreach $testNameList (@raw_data)
    {
     chomp($testNameList);
     print "$testNameList\n";
    }

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by chez View Post
    What i wanted to do is to display all items(flat file) in a directory into a combobox.
    Den display the content in the flat file once the item is selected.
    I have problem implementing it. Pls advice and guide me.
    Thanks

    Code:
    print "Content-type: text/html\n\n";
    print "<html><head>";
    print "<title>Test</title>";
    print "<meta http-equiv=refresh content=600>";
    print "</head><body topmargin=5 rightmargin=5 leftmargin=30>";
    
    print "<form name=\"inputList\" action=\"\" method=\"post\">";
    
    print qq|Test Name: <input type="Text" name="testName">|;
    
    @testList = `ls -1 /u/cgi-bin/test/List`;
    
    #list content
    	print "<select name=\"testDropList\">";
    for(@testList){
    	$testName = $_;	
           	print "<option value=\"\">$testName</option>";
    }
    	print "</select>";
    
    $data_file="testDropList";
    
    
    print <<END;
    <center>
    <p>&nbsp;</p>
    <p><font class=footer>
    </font><p>
    </center>
    </body></html>
    END
    
    open(DAT, $data_file) || die("Could not open file!"); 
    @raw_data=<DAT>; 
    close(DAT); 
    
    #display content
    foreach $testNameList (@raw_data)
    {
     chomp($testNameList);
     print "$testNameList\n";
    }
    see man page or perldoc for CGI module to simplify the code and look into perlfunc man page for lstat to use instead of ls -l.
    "I have problem implementing it." doesn't say too much.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •