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>