Answer the question
In order to leave comments, you need to log in
Why is the value not being passed from js to php?
Welcome all.
Explain why my value and JS are not being passed to PHP and how to do it correctly.
<script>
var abcd = 2222;
</script>
$GetVar = "<script>document.write(abcd)</script>";
console.log($GetVar);
Answer the question
In order to leave comments, you need to log in
You generally have a language written in some kind of PHJS.
You can transfer from PHP to JS like this:
<?php
$abcd = 1234;
?>
<script>
var abcd = <?= json_encode($abcd) ?>;
var abcd = <?= $abcd ?>;
console.log(abcd);
</script>
PHP is a server-side language and JS is a client-side language (runs in a browser). First, the PHP script will be executed, and only then the JS script will be executed.
For your task - you need to pass data to a php script, this can be done through a form or an ajax request
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question