Domain Empire

Insert php code into javascript

Spaceship
Watch
Impact
6
I've made a javascript and would like to know how to echo a value into the script.

Code:
iView.document.body.innerHTML = '<? echo $source; ?>';

that just pastes it as "<? echo $source; ?>".

Any ideas?
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
That should work if $source has a value. It should replace $source with whatever it's value is.

So if you had something like:

PHP:
<?
$source = "YourValue";
?>

iView.document.body.innerHTML = '<? echo $source; ?>';

The result should be:
Code:
iView.document.body.innerHTML = 'YourValue';

You can also do it as <?=$source?> for a little shortcut. :D

If it's just printing out <? echo $source; ?> then you may not have the short_open_tag enabled.
 
0
•••
source did have a value...
i registered it as a session too.
 
0
•••
Well like I mentioned above maybe your short_open_tag isn't enabled or something if you're sure their was a value in the variable. It could also be a problem with register_globals or the way you're assigning the value or something like that. Otherwise it would print it to the browser just like you expect. I would need to see how you're getting the values and such to see what's really going on. B-)
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back