Textarea text is determined by dropdown menu.

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
mattbranch12
Forum Newbie
Posts: 18
Joined: Thu Jul 09, 2009 3:14 pm
Location: Hagerstown, MD

Textarea text is determined by dropdown menu.

Post 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";

?>
unibroue
Forum Newbie
Posts: 4
Joined: Thu Jul 09, 2009 3:09 pm

Re: Textarea text is determined by dropdown menu.

Post 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!
mattbranch12
Forum Newbie
Posts: 18
Joined: Thu Jul 09, 2009 3:14 pm
Location: Hagerstown, MD

Re: Textarea text is determined by dropdown menu.

Post by mattbranch12 »

Thank you for replying so quickly. An example would be greatly appreciated.
Post Reply