1

I have this code and it should just work and echo the thing but it doesn't

<!DOCTYPE html>
<html>
  <body>
      <div id="colo" style='color:rgb(24, 209, 95)'>Yeet</div>
      <div id="color"></div>
      <button onclick="color();" style='width:100px; height: 75px;'></button>
    <script type="text/javascript"> 

      function color(){
        var rgb = document.getElementById("colo").style.color; 
        document.getElementById("color").innerHTML = rgb;
      }  
    <?php $abc = "<script>document.write(rgb)</script>"?>   

      </script>


<?php echo $abc;?>



  </body>
</html>

I tried placing the variable different but no

  • 4
    Possible duplicate of [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – VLAZ Sep 25 '19 at 11:53
  • you should **never** mix PHP and JS - and you definitely shouldn't be using PHP to create your JS. – treyBake Sep 25 '19 at 11:54
  • 1
    error should be `rgb is not defined` since the variable is defined inside of a function. – epascarello Sep 25 '19 at 11:56

1 Answers1

0

It works for me. You are using both PHP and JS so please be sure that you are running this on a php server as it will not work in an html file.

enter image description here

Connor Brown
  • 175
  • 6