JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
  #1  
Old March 10th, 2008, 04:46 AM
Chaosengine Chaosengine is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 1 Chaosengine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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>&nbsp&nbspSelect a library:</b>&nbsp&nbsp&nbsp  
<?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!

Reply With Quote
  #2  
Old March 12th, 2008, 06:38 AM
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 50 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 25 m 8 sec
Reputation Power: 1
Assuming...

Save the MYSQL data to a variable in PHP and POST it with a hidden element that does so, like, onButtonPress or some other function.

Then grab it from the POST with js.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Other - How to populate a TextArea from a Database based on Drop-Down Selection?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway