Jump to content

How to get the textarea to display the content that is selected from the dropdow


sarmenhb

Recommended Posts

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>

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.