-1

I have this code.

It's working fine for first var but its showing undefined variable for second.

How I suppose to solve this?

Here is my code:

<script>
  var p1 = "success";
  var time = document.getElementById("time").innerHTML;
</script>


<body>
  <div id="time">04:00</div>
  <?php
     echo "<script>document.writeln(p1);</script>";
     echo $timevalue = "<script>document.writeln(time);</script>";
  ?>
xxbinxx
  • 1,527
  • 11
  • 18

1 Answers1

0

You have to inverse the order

 <div id="time">04:00</div>

 <script>
    var p1 = "success";
    var time = document.getElementById("time").innerHTML;
 </script>  

 <?php
    echo "<script>document.writeln(p1);</script>";
    echo $timevalue = "<script>document.writeln(time);</script>";
  ?>
xxbinxx
  • 1,527
  • 11
  • 18
may saghira
  • 564
  • 9
  • 16