sarmenhb Posted November 28, 2007 Share Posted November 28, 2007 what im trying to do is, i have a drop down that displays all the files that are in the directory when the page loads. when a item is selected from the drop down list i want that file to load in the text area but i cannot get it to work, can someone tell me what im doing wrong? thanks, appreciate it. ============================== <? $path = "c:\\code\\"; $dir = opendir($path); ?> <form method="post" type=" <? $_SERVER['PHP_SELF'] ?>"> <label> <select name="select" id="select"> <? while ($listing = readdir($dir)) { echo "<option value='".$listing."'".$listing."'>".$listing."</option>"; } fclose($listing); $file = fopen($listing, "a+"); $size = filesize($fn); $text = fread($file, $size); fclose($file); ?> </select> </label> <br><br><br><br><br> <textarea name="name" cols="100" rows="10"><? echo $text; ?></textarea> <input type="submit" value="submit"/> </form> Quote Link to comment Share on other sites More sharing options...
AndIfNot Posted November 28, 2007 Share Posted November 28, 2007 Tested...works <?php $path = "test"; $dir = opendir($path); $getlisting = $_POST['listing']; ?> <form method="post" type=" <? $_SERVER['PHP_SELF'] ?>"> <label> <select name="listing" id="listing"> <option>Select One</option> <?php while ($listing = readdir($dir)) { if(($listing != ".")&&($listing != "..")){ if($listing == $getlisting){ $selected = "selected"; } else{ $selected = ""; } echo("<option onclick=\"form.submit();\" value=\"$listing\" $selected>$listing</option>\n"); } } $file = fopen("$path/$getlisting", "rw"); $size = filesize("$path/$getlisting"); $text = fread($file, $size); fclose($file); ?> </select><br> </label> <textarea name="name" cols="100" rows="10"><? echo $text; ?></textarea> <input type="submit" value="submit"/> </form> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.