SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post calling php function

    Hi, I have problem...my php function is not working in the onclick function...why is it not working.can you help me please on this.



    Code:
    function myonclickbutton(){
         var myphpfunc = '<?php echo myfunction();?>';
    }

    HTML Code:
    <a title="Save" onclick="myonclickbutton()" href="#" id="mybtn"><

    Thank you in advance

  2. #2
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    How do you expect the client side JavaScript to communicate with your server side php? That's why you use JavaScript, because you can't expect users to have php.

    But you should be more specific about what you're trying to accomplish here.

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,264
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    Are you confusing server-side PHP that runs before the page is rendered with client-side javascript that runs after the page has loaded?

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi,...I want that when i submit the form my php function will be executed in my onclick().

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,264
    Mentioned
    196 Post(s)
    Tagged
    2 Thread(s)
    The only way to do that is to send the message to the server, where the PHP function is.

    You need either another page load, or to use AJAX. Either way an HTTP request is needed.

  6. #6
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    Isn't this related to an older thread of yours?
    http://www.sitepoint.com/forums/show...ng-jQuery-ajax

  7. #7
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    The only way to do that is to send the message to the server, where the PHP function is.

    You need either another page load, or to use AJAX. Either way an HTTP request is needed.

    Ok Thank you...i have some question when i am trying to alert "hello" in my onclick.

    Code:
    function myonclick(){
     var mytest = "<?php echo 'hello';?>";
    
     alert(mytest);
    
    }
    it will alert to this
    <?php echo 'hello';?>
    ,it should be hello only without the php tags..

  8. #8
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,159
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by myty View Post
    Isn't this related to an older thread of yours?
    http://www.sitepoint.com/forums/show...ng-jQuery-ajax

    Nope,

  9. #9
    Non-Member
    Join Date
    Feb 2012
    Posts
    892
    Mentioned
    10 Post(s)
    Tagged
    0 Thread(s)
    OK, so it's all about JS?

    Code:
    function myonclick(){
     var mytest = "hello";
    
     alert(mytest);
    
    }


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •