Translate

Saturday, February 8, 2014

How to pass PHP variable to Javascript

   How to pass PHP variable to JavaScript



In this post we'll learn the best way  to pass PHP variable to javascript,It is really simple and easy. The example below will show you how to do it.

This is our PHP  code where we have assigned the value "Australia" to the variable $mycountry.



    $mycountry = 'Australia';
    
 


and this is our Javascript Code

<script>


  //solo imprimimos con un echo el contenido de la variable de php asignandola a una variable JS

var MynewVAr = '';


alert(MynewVAr);
 


</script>


This is quite easy this is the whole code:

<?php  


 $mycountry = 'Australia';
 

?>

<script>


  //solo imprimimos con un echo el contenido de la variable de php asignandola a una variable JS

var MynewVAr = '';


alert(MynewVAr);
 


</script>




No comments:

Post a Comment