javascript php variable
snippet in php

javascript php variable

user7716

<script type="text/javascript">
   var php_var = "<?php echo $php_var; ?>";
</script>

send php variable to javascript

user8875

<!DOCTYPE html> 
<html> 
  
<head> 
    <title> 
        How to pass variables and data 
        from PHP to JavaScript? 
    </title> 
</head> 
  
<body style="text-align:center;"> 
      
    <h1 style="color:green;">GeeksforGeeks</h1> 
      
    <h4> 
        How to pass variables and data 
        from PHP to JavaScript? 
    </h4> 
      
    <?php 
        $name = "Hello World"; 
    ?> 
  
    <script type="text/javascript"> 
        var x = "<?php echo"$name"?>"; 
        document.write(x); 
    </script> 
</body> 
  
<html>