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>

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.