Jump to content

javascript variable to php variable


baho

Recommended Posts

[code]
<html><body>
<script language="javascript">
var $i=5;
<?php $k = $i;?>
</script>
</body></html>[/code]
when you create the javascript variable, make it readable as a variable by PHP by using the PHP standard method of giving it a $ at the beginning.
PHP code is processed by the server before the browser processes your javascript.  Set your variables first in PHP.

[color=orange]<script language="javascript">[/color]
[color=orange]var [/color]<?php $k=5; echo('[color=orange]$k=[/color]'.$k); ?>[color=green];[/color]
[color=orange]alert($k);[/color]
[color=orange]alert("[/color]<?php echo($k); ?>[color=orange]");[/color]
<?php $i=$k; ?>
[color=orange]alert("[/color]<?php echo $i ?>"[color=orange]);[/color]
[color=orange]</script>[/color]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.