
March 10th, 2008, 04:46 AM
|
|
Registered User
|
|
Join Date: Mar 2008
Posts: 1
Time spent in forums: 1 m 59 sec
Reputation Power: 0
|
|
|
Other - How to populate a TextArea from a Database based on Drop-Down Selection?
I'm lreatively new to Javascript and even PHP.
My problem is that I want a Drop-Down list which is populated from a MySQL database and upon selection, I want to update the TextArea box with the appropriate description for the selected item in the list, which is also acquired from the MySQL database. I'm totally clueless and lost even after reading and trying out several methods I saw while surfing ard. Hoping someone here can enlighten me...
Below are my code snippets:-
PHP Code:
<b>  Select a library:</b>   
<?php
$query = "SELECT * FROM mydb.libraries;";
$result = @mysql_query($query);
// Check result
if (!$result)
{
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $query;
die($message);
}
?>
<select name='SVGLibraries' onChange='checkLibrary(); updateText();'>
<option value='invalid' <?php echo "selected"; ?>>-- Select a Library --</option> <br />
<?php
while ($row = mysql_fetch_array($result))
{
?>
<option value=<?php echo $row['id'] ?>><?php echo $row['name'] ?></option>
<?php
}
?>
</select>
<br /><textarea id="desc" name="desc" rows=5 cols=33 readonly value=<?php echo $row['description'] ?>></textarea>
<?php
mysql_free_result($result);
?>
My Javascript, which I don't know how to fill in to read from the Database. Nonetheless, below is a fixed text population, but it is not working and I don't know why:-
Code:
function updateText()
{
val = document.Form.SVGLibraries.options[document.Form.SVGLibraries.options.selectedIndex].value;
textbox = document.Form.desc;
// Temporarily display fixed Text
textbox.value = "Selected Library";
}
Let me know if you guys need more info..my code is kinda messy at the moment. Thanks in advance!
|