Want PHP database fields to be echoed in textarea inside javascript [modified]
-
I have a textarea with a name "DocContent" inside Javascript. I want the content of a field [called documentcontent]from database to be displayed inside the "DocContent" text when an event is fired inside javascript. anyone with a solution? you may look at my partial code:
$query="select documentcontent, uploadDate from document where uploadDate=(select max(uploadDate) from document where documenttype='index' and documentid=12 )";
$result=mysql_query($query);if ($row = mysql\_fetch\_array($result)) { extract($row); }
?>
function Eventhandler(selectobj){
if(selectobj.value=='Modify')
{document.FormUpdate.DocContent=<?php echo $row\['documentcontent'\];???>;
}
}modified on Monday, February 9, 2009 11:48 AM
-
I have a textarea with a name "DocContent" inside Javascript. I want the content of a field [called documentcontent]from database to be displayed inside the "DocContent" text when an event is fired inside javascript. anyone with a solution? you may look at my partial code:
$query="select documentcontent, uploadDate from document where uploadDate=(select max(uploadDate) from document where documenttype='index' and documentid=12 )";
$result=mysql_query($query);if ($row = mysql\_fetch\_array($result)) { extract($row); }
?>
function Eventhandler(selectobj){
if(selectobj.value=='Modify')
{document.FormUpdate.DocContent=<?php echo $row\['documentcontent'\];???>;
}
}modified on Monday, February 9, 2009 11:48 AM
It really depends what your system is like: 1. If you have content that is retrieved from the server that is independent of user input, then all you need to do is request the data from the server when the page loads, and store it somewhere in a JavaScript global variable, for instance. It can then be inserted into the textarea when you need it to be. 2. If you have content that is retrieved from the server based on user input, then you would need to use AJAX (Asynchronous Javascript And XML), to make a request to the server, run your PHP script and return the data from the database can then be returned to your page and inserted into your textarea using JavaScript. Take a look at this article which might help, or look around on Google, for which there are lots of resources on the subject matter. Regards, --Perspx
"A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year."
-Andrew Tanenbaum
"Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer."
-Fred Brooks -
It really depends what your system is like: 1. If you have content that is retrieved from the server that is independent of user input, then all you need to do is request the data from the server when the page loads, and store it somewhere in a JavaScript global variable, for instance. It can then be inserted into the textarea when you need it to be. 2. If you have content that is retrieved from the server based on user input, then you would need to use AJAX (Asynchronous Javascript And XML), to make a request to the server, run your PHP script and return the data from the database can then be returned to your page and inserted into your textarea using JavaScript. Take a look at this article which might help, or look around on Google, for which there are lots of resources on the subject matter. Regards, --Perspx
"A refund for defective software might be nice, except it would bankrupt the entire software industry in the first year."
-Andrew Tanenbaum
"Einstein argued that there must be simplified explanations of nature, because God is not capricious or arbitrary. No such faith comforts the software engineer."
-Fred Brooks