Solved

JavaScript to write and execute PHP script code to a div tag

Posted on 2009-04-09
3
816 Views
Last Modified: 2012-08-13
I know php is server based and only executes when the page first loads (at run time)

my question is;
Can you use JavaScript to write and execute PHP script loaded from an external file?

this is what Ive tried;
<script type="text/javascript">
function showAreaOfTown(){
      var target = document.createElement( "script" );
      target.setAttribute( "src", "areaOfTown.php" );
      document.getElementById("areaOfTown").appendChild( target ); //the div tag
}
</script>

0
Comment
Question by:Cybervanes
  • 2
3 Comments
 
LVL 2

Author Comment

by:Cybervanes
ID: 24112250
nobody has any ideas?
0
 
LVL 19

Assisted Solution

by:LordOfPorts
LordOfPorts earned 20 total points
ID: 24112346
One option would be to use AJAX http://www.w3schools.com/Ajax/ajax_intro.asp to call a specific PHP page which would perform a certain task and return a result which you can then assign to a DIV on the page, you could even pass code to the page through a URL parameter and then use the eval http://us2.php.net/eval function to execute the code.
0
 
LVL 2

Accepted Solution

by:
Cybervanes earned 0 total points
ID: 24168701
i decided to build a flash application instead. thanks.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question