?
Solved

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

Posted on 2009-04-09
3
Medium Priority
?
823 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 80 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month15 days, 22 hours left to enroll

850 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