Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Want PHP database fields to be echoed in textarea inside javascript [modified]

Want PHP database fields to be echoed in textarea inside javascript [modified]

Scheduled Pinned Locked Moved Web Development
databasejavascriptphpmysqlquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dambod
    wrote on last edited by
    #1

    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

    P 1 Reply Last reply
    0
    • D Dambod

      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

      P Offline
      P Offline
      Perspx
      wrote on last edited by
      #2

      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

      D 1 Reply Last reply
      0
      • P Perspx

        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

        D Offline
        D Offline
        Dambod
        wrote on last edited by
        #3

        thanks perspx, i had some clues from your reply. But do u have any sample code to do so based my sample? thanks again

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups