Skip to content Skip to sidebar Skip to footer

Pass Javascript Var Into Php Var

var javascript_variable = $('#ctl00').text(); document.write(javascript_variable); I want to pass the above javascript_variable into p

Solution 1:

You cannot do that.

PHP is executed on your server. Javascript on the otherhand is executed on your client's machine in the browser.

There are two different execution context. While you can pass a PHP variable into Javascript, you cannot do the opposite since PHP is executed first and the JavaScript code is the output of your PHP code.

If you want to send a Javascript variable to PHP, you have to do with in a separate request either via a cookie or an AJAX request. Here's an example:

$.ajax({
  url: 'receivingScript.php',
  data: {'value': $("#ct100").text()}
});

Post a Comment for "Pass Javascript Var Into Php Var"