Solved

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

Posted on 2009-04-09
3
807 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now