0

if i make a variable in javascript with this script

var kakakSisa        = 10;

and i wanna call it in PHP for example

<?php echo <script type="text/javascript">kakakSisa;</script> ?>

and that doesn't work!! how i can make it work?

Jack
  • 1
  • 4
  • possible duplicate of [Access a JavaScript variable from PHP](http://stackoverflow.com/questions/2338942/access-a-javascript-variable-from-php) – jpcanamaque Jan 16 '15 at 02:51

2 Answers2

0

Use AJAX to communicate client and server side.

$.get('/path/to/file', kakakSisa: 10, function(data, textStatus, xhr) {
  /*optional stuff to do after success */
});

Get variable in php using $_GET['kakakSisa'];

Rafael
  • 7,605
  • 13
  • 31
  • 46
0

You can't use javascript variable in php code. Php code run's on the serverside and javascript code runs in the client side (If you are not using Node.js). You can't ask the browser to run php code.

Your variable loc will have a value only when the code reaches the browser.

If you want to get some value from server and combine it with javascript variables then do the following.

Use an ajax request and send the desired values to server. The server will return with a response. Use that response text and store it in your action variable.

  • if i help, please accept my answer in the left corner of my answer <- –  Jan 16 '15 at 03:09