0

I have a function in JavaScript called message. I want to call this function inside PHP.

I've tried the following, but it does not work.

<script>
  $(document).ready(function(){
    function JsClass () {  
      this.mensaje = function() {
       alert("You call the JAVASCRIPT FUNCTION IN PHP");`
      }
    }
  });
</script>

<?php               
  function ClasePhp($user, $pw) {
    function callJsFunction() {
  ?>             
    <script>
      var javaClass = new JsClass();
      javaClass.message();
    </script>    
  <?php
    }
  }
?>
Sergio Diaz
  • 33
  • 10
  • 3
    PHP executes first, javascript second. They don't work together. What does the JS function do? You could send an AJAX request from the JS to call PHP functionality. – chris85 Jan 07 '17 at 18:54
  • chris85 ok bro, (sorry my english) so to PHP and JS work togheter, the unique way is by AJAX requesting?, so i need to learn more about AJAX request to comunicate with PHP – Sergio Diaz Jan 07 '17 at 19:12
  • That is correct. Also use the `@`, notifications aren't sent otherwise. – chris85 Jan 07 '17 at 19:55
  • [How to call a JavaScript function from PHP?](http://stackoverflow.com/q/1045845) –  Jan 07 '17 at 19:58
  • @chris85 Very thanks bro, this is an important tip to me to understand how this powerful languages works. – Sergio Diaz Jan 07 '17 at 21:29

0 Answers0