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()
;
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()
;
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
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.