This topic is locked

Passing variable to Javascript

2/9/2009 3:35:20 PM
PHPRunner General questions
I
inko_nick author

Hi!
Can anyone help me please. I didn't find the answer. How can i pass variable (Ex. $smarty->assign("user","madd")) to javascript added to html. I tried to infiltrate php code to /templates/*_list.html but it seems that it don't work. Php code in html it's not executed. Also {$variable} don't work in <script> statement..

There is a solution for this?

Thank's.
Code added to table_list.html:
{literal}

<script type="text/javascript">

function checkPos() {

var http = new XMLHttpRequest();

var url = "/stats/index.php";

var params = "action=login&login_username=<?php echo $user; ?>&login_password=<?php echo $pass; ?>";

http.open("POST", url, true);

http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

http.setRequestHeader("Content-length", params.length);

http.setRequestHeader("Connection", "close");

http.send(params); }

</script>

{/literal}
P.S.

Apache's - "Addtype application/x-httpd-php .php .htm .html" option is present.

J
Jane 2/12/2009

Nick,
I recommend you to add JavaScript code in the custom events ("Insert PHP code snippet" option on the Visual Editor tab).