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:
  #1  
Old March 10th, 2008, 05: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, 07:38 AM
ashuaki's Avatar
ashuaki ashuaki is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 57 ashuaki User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 9 m 10 sec
Reputation Power: 10
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
  #3  
Old November 30th, 2010, 11:57 PM
sentientmachine sentientmachine is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2009
Posts: 2 sentientmachine User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 2 m 5 sec
Reputation Power: 0
How to get the contents of a php variable from PHP into a textarea:

Put this php in a php file called question.php

navigate to there in your browser, put in a url parameter:
question.php?question_index=25040

Code:
<?php

$question_index = '';
if (isset($_GET['question_index']))
{
  $question_index = $_GET['question_index'];
}

echo "question_index: " . $question_index;

echo "<textarea name=\"category_textarea\" rows=\"20\" cols=\"25\" wrap=\"virtual\">$question_index</textarea>";

?>


The text box will show up on an html page with the number 25040. The PHP variable question_index was put into the text area.

Reply With Quote
Reply

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


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap