Pass Javascript variable value to php variable
We can use variable value in JavaScript in PHP, but we can not directly use value in client side (JavaScript) in server side PHP.
Here is simple solution to use value in client side (JavaScript) variable in server side PHP varaible :
we need to pass values in JavaScript to server side using location.href JavaScript function in the url……
location.href=”blog_app.php?name=” +name;
Here is example code
note : create single blog_app.php php file, add following sample codes to test this.
<html> <head> <script language=javascript> function promptor() { var name=prompt("Please enter your Email","Enter your email"); // passing javascript if (name!=null && name!="") { location.href="blog_app.php?name=" +name; } else { document.writeln("please fill your email"); } } </head> <body> <input name="Downlaod" type="submit" id="Downlaod" onclick="promptor()"/> </body> <?php if(isset($_GET['name'])) { $email=$_GET['name']; echo $email; } ?> </html>
Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts
If you want any of my script need to be customized according to your business requirement,
Please feel free to contact me [at] muni2explore[at]gmail.com
Note: But it will be charged based on your customization requirement