Filling a text area with options from a select tag

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
phphunger
Forum Commoner
Posts: 45
Joined: Tue Aug 11, 2009 11:56 pm

Filling a text area with options from a select tag

Post by phphunger »

Hi techies,

As i have struck at placing selected dropdown values into the textarea using php. Can any one tell me how to fill textarea with the selected values of dropdownlist.
Actually my requirement is i want to upload a CSV file into the database and fromthat CSV file i want to take only the header values into the textarea. Can anyone give solution for that.

Thanks in advance.

My sample code:

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <script language="javascript" type="text/javascript">
            function dropDownValue()
            {
                document.fileform.txt.value +="<?php $data[$c] ?>";
            }
        </script>
    </head>
    <body>
    
      <form action='' name='fileform' method='post' enctype="multipart/form-data">
      Type file name to import:<br>
      <input type='file' name='filename' size='20'/><br/>
      <input type='submit' name='submit' value='submit'/>
<?php
include "connect.php";
if(isset($_POST['submit']))
   {
$row = 1;
 
$temp_loc = $_FILES['filename']['tmp_name'];
//$handle = fopen("$filename", "r");
$handle = fopen("$temp_loc", "r");
 
if (($data = fgetcsv($handle, 1000, ",")) !== FALSE) 
{
 
    $num = count($data);
    echo "<p> $num fields in line $row: <br /></p>\n";
    $row++;
    
    echo "Select: <select name='nam'>";
    echo "<option value='select'>select</option>";
    
    for ($c=0; $c < $num; $c++) 
    {
        //echo $data[$c] . "<br />\n";
        
        echo "<option value='$data[$c]'>$data[$c]</option>";
    }
        
    echo "</select>";
    echo "</br>";
    
    echo '<textarea name="txt" rows="10" cols="30"></textarea>';
    echo "</br>";
    
    $num = count($data);
    echo "<p> $num fields in line $row: <br /></p>\n";
    $row++;
    
    echo "Select: <select name='nam'>";
    echo "<option value='select'>select</option>";
    
    for ($c=0; $c < $num; $c++) 
    {
        //echo $data[$c] . "<br />\n";
        
        echo "<option value='$data[$c]'>$data[$c]</option>";
    }
        
    echo "</select>";
    echo "</br>";
 
    
}
fclose($handle);
    }
?>
    </form>
  </body>
 </html>
phphunger
Forum Commoner
Posts: 45
Joined: Tue Aug 11, 2009 11:56 pm

Re: Filling a text area with options from a select tag

Post by phphunger »

Hello can anyone provide solution for this post...Please..
Post Reply