Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

textarea value from database

Status
Not open for further replies.

tomvdduin

Programmer
Sep 29, 2002
155
NL
Hi,

I want to insert some data into an textarea element from a database. The only point is, that the data must me manipulated bt a javascript. I tried the following, but that doesn't work: (client-side code, the string 'name#^...' is generated by php)


<TEXTAREA name="abonnee_etiket" rows="6" cols="40" value="formatEtiket('name#^address#^city#^country')"></TEXTAREA>

formatEtiket is a javascript function that puts an \n in place of the #^. It performs some other functios, though.

The above is not working, but how can I?
 
I forgot to say that the function formatEtiket returns a string.
 
Won't work... there are two ways to assign value to textarea:
Code:
<TEXTAREA>blah</TEXTAREA>
or
Code:
document.forms[0]["abonnee_etiket"].value="blah";
 
Here is how I would attack the problem...

Add an ID to the textarea and remove the value code:
Code:
<TEXTAREA id="myTxt" name="abonnee_etiket" rows="6" cols="40" value=""></TEXTAREA>

Add a function to set the value using your existing function that returns a string:
Code:
<script>
function initialise()
{
  document.getElementById('myTxt').value = formatEtiket ('name#^address#^city#^country');
}
</script>

Finally, set the new function to execute once the page has loaded:
Code:
<body onload="initialise()">

Hope this gets you started!
Jeff
 
And you can let PHP do the job for you..

Code:
<html><head><title>First PHP Page</title>
</head><body>
<p>test</p>
<textarea name="texta" cols="20" rows="5">
Output from PHP is:
<?php
$dbinfo = array ("fname"=>"Billy", "lname"=>"Bob","pone"=>"465-9876");
foreach($dbinfo as $key=>$value){
print ("$value\n"); }
?>
</textarea>
</body></html>

HTH

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top