I have JavaScript function with pass one parameter to
<script type="text/javascript">
function myfun(var1)
{
var returnVal = "<?php echo get_value(); ?>";
}
</script>
I want to pass JavaScript variable i.e. var1 to get_value();
zzlalani
24.6k16 gold badges48 silver badges73 bronze badges
asked Nov 1, 2013 at 6:13
Andy Martin
1791 gold badge2 silver badges9 bronze badges
-
and why you want to do this?zzlalani– zzlalani2013年11月01日 06:17:44 +00:00Commented Nov 1, 2013 at 6:17
-
PHP runs on the server. First. It generates HTML/JavaScript which is run on the client. Later. To pass data back to PHP you need to send it to the server (form post, AJAX, SignalR, etc).user2864740– user28647402013年11月01日 06:17:45 +00:00Commented Nov 1, 2013 at 6:17
-
stackoverflow.com/questions/1917576/…jfmbrennan– jfmbrennan2013年11月01日 06:20:40 +00:00Commented Nov 1, 2013 at 6:20
-
I get you @user2864740 my mistakeJust code– Just code2013年11月01日 06:20:57 +00:00Commented Nov 1, 2013 at 6:20
-
You need to use Ajax to pass javascript value into PHP.Krish R– Krish R2013年11月01日 06:22:47 +00:00Commented Nov 1, 2013 at 6:22
2 Answers 2
You can't do that.
PHP is executed server-side, Javascript client-side. What that means is, the PHP code is executed before the Javascript.
However, you could use AJAX to call a PHP function from Javascript.
You can refer : how to pass the JavaScript variable to the php function
answered Nov 1, 2013 at 6:19
Sridhar R
20.4k7 gold badges41 silver badges35 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Try this:
PHP is executed server-side.
Javascript client-side.
It means, the PHP code is executed before the Javascript.
Here what you can do is to use jquery-ajax.
Inside that call a URL which returns variable you want.
Use that in result of ajax.
- Thanks
answered Nov 1, 2013 at 6:37
Anand Solanki
3,4254 gold badges19 silver badges27 bronze badges
Comments
default