how to use php integer variable in javascript as integer variable -


i have passed php integer variable $number javascript. can't access php variable without using quotation

<script>  var number = '<?php echo $number?>'; </script> 

if use quotation can accessible don't integer value actually. became string since use quotation. without quotation can't anything.

i have googling don't appropriate answer yet.

how integer value.

for int simple remove single quotes

<script>      var number = <?php echo $number ?>; </script> 

note : make sure $number should not empty . if it's empty use ternary operator if statement handle . var number =<?php echo !empty($number)? $number:0 ?>;


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -