Please support us by disabling ad blocker for smarttutorials.net ...

Pass Javascript variable value to php variable

Posted by & filed under JAVASCRIPT, PHP.

We can use variable value in JavaScript in PHP, but we can not directly use value in client side (JavaScript) in server side PHP.

how to pass javascript variable value to php

How to pass JavaScript variable value to 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] muni[at]smarttutorials.net

Note: But it will be charged based on your customization requirement

Get Updates, Scripts & Other Useful Resources to your Email

Join 10,000+ Happy Subscribers on feedburner. Click to Subscribe (We don't send spam)
Every Email Subsciber could have access to download 100+ demo scripts & all future scripts.

Get Instant Script Download Access!