Page 1 of 1

Populating list box and passing value

Posted: Tue Mar 02, 2004 11:59 am
by rjseals
I have a main web folder that has several sub directories in it. I want to populate a list box with these directories and when the user chooses a value out of the dropdown list it will pass that value to another page.
html...

Code: Select all

(test.php) 


<form action="done.php" method="post"> 
<select name = input> 
<? 
$dir = "/web/directory/";  //sets directory path 
    
    
      // Open a known directory, and proceed to read its contents 
        
    
if (is_dir($dir)) 
&#123;  
    if ($dh = opendir($dir)) 
   &#123; 
        while (($file = readdir($dh)) !== false) //while files and folders are being read    
      &#123;      
             if (filetype($dir . $file) == dir) //if the filetype is a directory and not a file 
         &#123; 
              
    echo '<option>'.$file.'</option>'; 
    
         &#125; 
      &#125; 
        closedir($dh); 
   &#125; 
&#125; 
    
    
?> 
</select> 
<input type="submit" value="Edit"> 


---------------------------------------------------------------- 

(done.php) 

<html> 
<form> 
<input type="text" value="<?echo $_POST&#1111;"input"]; ?>"> 
</form> 
</html>
The code from the test.php populates the dropdown list just fine but it won't pass the variable selected to done.php. I read that I need to give each option a key but wasn't sure if that was true for my situation or how to go about that.

Can anyone give me any pointers?

Thanks!

Posted: Tue Mar 02, 2004 4:27 pm
by Crashin
Try:

Code: Select all

echo '<option value="$file">'.$file.'</option>';