send php variable to javascript
snippet in php

javascript php variable

user1321

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

how to use php echo data in javascript

user7695

<?php
$php_variable = 'string'; //Define our PHP variable. You can of course get the value of this variable however you need.
?>			
        <script> js_variable_name = "<?php echo $php_variable; ?>";</script>

send php variable to javascript

user4679

<!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> 

how to get a variable from php to javascript

user6469

<script type="text/javascript">
// boolean outputs "" if false, "1" if true
var bool = "<?php echo $bool ?>"; 

// numeric value, both with and without quotes
var num = <?php echo $num ?>; // 7
var str_num = "<?php echo $num ?>"; // "7" (a string)

var str = "<?php echo $str ?>"; // "A string here"
</script>