Reading Time: 2 minutes
How to pass JavaScript variables to PHP
There are many ways to pass JS Variables to PHP. PHP is the scripting language used on the server, while JavaScript is used on the client. The best technique to send a JavaScript variable to PHP.
Method 1:
In this example, JavaScript variables are passed to PHP using the GET/POST method and form elements. The PHP GET and POST actions allow access to the contents’ form. The client transmits the form data in the form of a URL, such as when the form is submitted
example1.php
<?php
if (isset($_GET)) {
$result = $_GET['data'];
echo 'Submitted data ' . $result;
}
?>
m