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
3762 silver badges11 bronze badges
asked Mar 29, 2015 at 6:42
1

1 Answer 1

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.

answered Mar 29, 2015 at 6:49
Sign up to request clarification or add additional context in comments.

3 Comments

This ideally suites for comment and not as answer.
"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.
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.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.