TitaN TitaN - 1 year ago 56
Javascript Question

Text in div converted to comment

I'd like to "send" php from div, line this:

<div id='php'><?$login="login"; $password="password";?></div>

where "login" and "password" is variable.

but when i try to do it

document.getElementById('php').innerHTML = "<?$login=" + login + ";$password=" + password + ";?>"

But this text coming as comment
and it's happened EVERY time, when i try to add
<? echo(\"text\"); ?>
it's not work too.

How i can manage php from js & element.innerHTML with div?

Answer Source

You can't use PHP values in a javascript document. Instead, assign them globally in your PHP document that your js file can use:

In your game.php:

<script type="text/javascript">
   var login = "<?php echo $login; ?>";
   var password = "<?php echo $password; ?>";

Then you can use those values in your javascript file:

function Start()
    php.innerHTML = 'login:'+login+'password:'+password;

Tweak your innerHTML string as needed.