在PHP中创建和调用JavaScript函数

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.

I am not aware whether a similar question like this has been posted on this forum before. If it has then the mods can take a call and delete this post and send me a PM containing the link to the similar question. :D

Thank you in advance.


Thank you all very much for your replies. :)

The solution that you have given me is in HTML; but how do I achieve this in PHP?

<script>

function myFunction() {
  alert("Clicked");
}

</script>

<button onclick="myFunction()">Click me</button>

Do it like this?

<input id="mybutton" type="button" target="_self" onclick="functionname(), return false;" name="mybutton" value="Click me!" />

JavaScript which normally goes in head section.

<script type="text/javascript">
      function yourFunction() {

             alert("Helloc click ");
       }

    </script>

Your HTML

  <input onclick="yourFunction(); " value="value">

To start learning basic JavaScript a tutorial available here .