I have a form on a page where users can save information, and a dropdown that pulls those saved files from the directory they saved them to. What I would like is when they go to that page, is that when they select the filename from the dropdown box, it places the name of the file in the input box "CodeDescription" field and the information on the file in the textarea "Code" , however I am unsure how to go about parsing that. Below is my current code.

<input type="hidden" name="Action" value="EDIT" /><input type="hidden" name="Selection"  id="Selection" value="-1"><div>Below is the list of your saved codes. To edit your codes, select it from the list.</div>
    <select> 
    <?php 
    $directory = $directory = 'users/' . $_SESSION['username'];

    $files = scandir( $directory ) ;

    foreach( $files as $file )
    {
    if ( ! is_dir( $file ) )
    {
    echo "<option>" . $file . "</option>";
    }
    }
    ?>
    </select>
            <h3>Saved Codes</h3>


            <form method="post" action="/evo/avsaveprocess.php">

                <input type="hidden" name="Action" value="SAVE" />
                <input type="hidden" name="CodeId" id="CodeId" value="0" />
                <table width="100%" border="0">

                    <tr>
                        <td>Description:</td>
                        <td><input type="text" name="CodeDescription" size="40" maxlength="50" id="CodeName" value="" /></td>
                    </tr>

                    <tr>
                        <td valign="top">Code:</td>
                        <td>
                            <textarea rows="10" style="width:99%" name="Code" id="CodeValue"></textarea>
                        </td>
                    </tr>

                </table>

                <input type="submit" value="Save" />
                </form>

$("#CodeName").val($("#dropdown_id").val())

this simple line get val of dropdown and populate text field

Thank you Kamran I apologize I missed your response earlier while working on this. I am uncetain exactly where I would need to enter that, my updated php and code I have linked below since it won't let me edit my original post. I actually have two fields that I want to populate. ID=CodeName is the name of the file I'm trying to pull (which is the name from the selector) and then have the contents of that file displayed in ID=CodeValue

<input type="hidden" name="Action" value="EDIT" /><input type="hidden" name="Selection"  id="Selection" value="-1"><div>Below is the list of your saved codes. To edit your codes, select it from the list.</div>
<select size="1" name="CodeList" id="CodeList" onchange="CodeChange();"><option value="0">(Add New Code)</option>
<?php 
   $directory = $directory = 'users/' . $_SESSION['username'];
   $filesContents = Array();
   $files = scandir( $directory ) ;

   foreach( $files as $file )
 {
   if ( ! is_dir( $file ) )
 {
   $filesContents[$file] = file_get_contents($directory , $file);

  echo "<option>" . $file . "</option>";
 }
}
?>
</select>
    <h3>Saved Codes</h3>
    <form method="post" action="/evo/avsaveprocess.php">

     <input type="hidden" name="Action" value="SAVE" />
     <input type="hidden" name="CodeId" id="CodeId" value="0" />
     <table width="100%" border="0">
         <tr>
         <td>Description:</td>
         <td><input type="text" name="CodeDescription" size="40" maxlength="50" id="CodeName" value="" /></td>
          </tr>
          <tr>
          <td valign="top">Code:</td>
          <td>
            <textarea rows="10" style="width:99%" name="Code" id="CodeValue"></textarea>
               </td>
                </tr>
            </table>
            <input type="submit" value="Save" />
            </form>

Thank you Kamran, using your code I was able to get the proper jquery functionality to populate the file name into one text field, now working on figuring out how to populate the contents of that file.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.