-8

In my php script I have variable like below.

$duration = 60;

Now I'm accessing the above PHP variable in javascirpt.

<script type="text/javascript">
    var phpVar = '<?php echo $duration; ?>';
    console.log(phpVar );
 </script>

But in the console I'm getting the whole data instead of 60. That is, output is

 '<?php echo $duration; ?>'

Please help me how to access the php variable properly.

Thanks.

user2636874
  • 889
  • 4
  • 15
  • 36

1 Answers1

-1
<script type="text/javascript">
  $(document).ready(function(){
  var phpVar = <?php echo $duration; ?>;
  console.log(phpVar);
});

Put $duration instead if $simple.