2013-12-09 07:13
浏览 93


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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douzhicai7148
    douzhicai7148 2013-12-09 07:20
    function myFunction() {
    <button onclick="myFunction()">Click me</button>
    点赞 评论
  • dongyoucha0645
    dongyoucha0645 2013-12-09 07:20

    Do it like this?

    <input id="mybutton" type="button" target="_self" onclick="functionname(), return false;" name="mybutton" value="Click me!" />
    点赞 评论
  • duanbei7005
    duanbei7005 2013-12-09 07:21

    JavaScript which normally goes in head section.

    <script type="text/javascript">
          function yourFunction() {
                 alert("Helloc click ");

    Your HTML

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

    To start learning basic JavaScript a tutorial available here .

    点赞 评论