I have just started learning how to create web applications in PHP after migrating from ASP.NET.
I wanted to know how to integrate JavaScript with PHP. For example, there is a Home.php page that resides in the website’s root folder. The page has an HTML button on it and a simple JavaScript function that contains code for a pop-up window that says, “Hello!” I want to call this function at the click event of this HTML button.
Can anyone please help me? I know how this can be achieved in ASP.NET. I want to know how it can be done in PHP. After getting the solution to this problem, I will learn move to AJAX and then jQuery.
How do I achieve this in PHP?
Advertisement
Answer
<script> function myFunction() { alert("Clicked"); } </script> <button onclick="myFunction()">Click me</button>