Why my onclick function in button that is echo by php cannot work?

  echo, html, javascript, onclick, php

I do not know why this cannot work. It can output a button element but the onclick function cannot work at all. Not even an alert box pop up. PLS help.

<!DOCTYPE html>
    <html>
    <body>
    
    
    <?php $name = "John"; 
    echo "<button type='button' onclick='callYou('".$name."')'> click me </button>";
    ?>
    
    <script>
      function callYou(name) {
          if(confirm("Are you sure?")) {
             $greeting = "hello"+name;
             echo $greeting;
          } else {
             echo "nothing";
          }
      }
    </script>
    </body>
</html>

Source: Ask PHP

LEAVE A COMMENT