0

When clicking a button, I would like to call a function and pass a recipe ID. The function will then open a modal window but currently receiving an error - myFunction is not defined.

<button type="button" onclick="myFunction(<?php echo $recipeID ?>)" class="btn btn-info btn-lg">Open Modal</button>

<script>

function myFunction($recipeID){
    echo $recipeID;
    echo "<script type='text/javascript'>
        $(document).ready(function(){
            $('#myModal').modal('show');
        });
    </script>";
}
?>

  • 5
    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) – aynber May 22 '18 at 16:19

2 Answers2

0

You are calling an PHP function in javascript. PHP is executed first on server side and after that javascript on client side.

0

myFunction is defined on server-side, that is, this function is on the server. You try to call it via Javascript in the browser, but the function is not defined there. You will need to change the definition of your button to

<button type="button" onclick="$('#myModal').modal('show');" class="btn btn-info btn-lg">Open Modal</button>
Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175