Page 1 of 1

Textarea text is determined by dropdown menu.

Posted: Thu Jul 09, 2009 3:32 pm
by mattbranch12
I need to create a textarea and dropdown menu. I need the dropdown menu to determine what text will be displayed in the textarea. Both the dropdown menu and the textarea will be pulling information from a mysql db. If anyone has already created a solution for this could you please post the solution or where i could view the solution as i am unable to find one.

Here is what I have came up with so far. The only thing that shows up in the textarea is the first listed content field in the table.

<?php
$result = @mysql_query("SELECT parent_id, label, id FROM dyn_menu");

print "<select name =\"id\">\n";
while ($row = mysql_fetch_assoc($result)){
$none = 'none';
$id = $row['id'];
$label = $row['label'];
$del = $row['label'];

print "<option value=$id name=sub>$label";
}

print "</select>\n";
print "</p>\n";

$cool = @mysql_query("SELECT content FROM `page` WHERE `label`='$label'");

do
{
$id1 = $row2['id'];
$content = $row2['content'];
}
while($row2 = mysql_fetch_assoc($cool));

echo "<textarea cols=\"80\" rows=\"15\" wrap=\"ON\" name=\"body\">".stripslashes($content)."</textarea><br />\n";

?>

Re: Textarea text is determined by dropdown menu.

Posted: Thu Jul 09, 2009 4:15 pm
by unibroue
you'll need to do that in AJAX ...

that's quite easy to do, but that will require more work than just a simple SQL statement!

Your select will have a function set on the onChange event, and this function will create a XMLHTTPREQUEST and ask another php script to return the result of a SQL query for a certain id! Then the XMLHTTPREQUEST will be able to update the textarea using what the script returned!

Ajax can be tricky at first, but i can send an example if needed!

Re: Textarea text is determined by dropdown menu.

Posted: Thu Jul 09, 2009 10:47 pm
by mattbranch12
Thank you for replying so quickly. An example would be greatly appreciated.