TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 09-27-2010, 02:35 AM   #1 (permalink)
The Acquainted
 
Join Date: Feb 2008
Posts: 107
Thanks: 3
CΛSTΞX is on a distinguished road
Book How to use variable in javascript funtion ?

I want to echo the variable when I use test(); fuction. I meanwhen I use the variable with this function like test(john) , how to use it in that php snippet. Anyone knows ?

PHP Code:
<script type="text/javascript">
function test(){
document.getElementById("php_code").innerHTML="
<?php echo "hello"?>
";
}
</script>
__________________
Downloadic
infolizer
Send a message via MSN to CΛSTΞX
CΛSTΞX is offline  
Reply With Quote
Old 09-27-2010, 04:15 AM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

What I think you are trying to do is impossible, PHP can not be executed from javascript because they happen at different stages. Here is a simplified breakdown of a web request

Browser makes request to page -> Server gets request and information and processes page (PHP, ect...) -> Page outputs HTML back to browser -> Browser processes client side stuff (HTML, Javascript, flash, ect).

The PHP is done running and has already sent its output by the time the first line of javascript runs.

The only way to get a similar outcome is to use ajax.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Easily Format JSON using PHP and Interpret using Javascript Wildhoney Advanced PHP Programming 13 02-01-2013 11:05 AM
[Tip] Variable Prefixes bluesaga Tips & Tricks 24 10-22-2012 09:40 AM
Building Javascript PHP problem captainmerton Absolute Beginners 2 10-31-2009 10:02 AM
how would i echo this javascript variable sarmenhb Javascript, AJAX, E4X 1 12-03-2008 02:06 PM
What is a Variable? codefreek Absolute Beginners 7 07-01-2008 08:29 PM


All times are GMT. The time now is 10:55 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design