0

Can i pass the javascript variable to php variable..like this..

 var canvas = document.getElementById("canvas");
 var data = canvas.toDataURL("image/png");

 var newImg = document.createElement("img"); // create img tag
 newImg.src = url;
 var can =  document.body.appendChild(newImg);

<?php
   $canvas = "<script>document.write(can)</script>";
   echo $canvas;
?>

Is possible to pass that javascript variable to php variable ?

bayblade567
  • 270
  • 1
  • 10
manan vyas
  • 52
  • 1
  • 11
  • possible duplicate of [How to pass JavaScript variables to PHP?](http://stackoverflow.com/questions/1917576/how-to-pass-javascript-variables-to-php) – D4V1D Mar 29 '15 at 06:48

1 Answers1

1

"You cannot pass variable values from the current page JavaScript to the current page PHP code... PHP code runs at the server side and it doesn't know anything about what is going on on the client side." - How to pass JavaScript variables to PHP?

Basically, your PHP will run first, then the HTML page will be rendered with the JavaScript.

Community
  • 1
  • 1
Drakes
  • 23,254
  • 3
  • 51
  • 94
  • This ideally suites for comment and not as answer. – CuriousMind Mar 29 '15 at 07:14
  • "Is possible to pass that javascript variable to php variable?" - He asked about that variable 'can' and I answered. He can ask another question about different ways to accomplish something similar if he likes. – Drakes Mar 29 '15 at 07:25
  • Agreed as well, answered the question that was asked. Then gave extra information. Just because extra information was included, does not make it a comment of subject. – Evan Carslake Mar 29 '15 at 12:31