Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,997
    Thanks
    15
    Thanked 234 Times in 234 Posts

    Javascript Alert

    If you like good one liners, here's one. You put the function on a page that you always include, in my case the menu page, and call it from anywhere below where the data is generated.
    PHP Code:

    function jsAlert($msg){echo '<script type="text/javascript">alert("'.$msg.'");</script>"';}

    jsAlert('smith'); 
    So you don't need to scour through 100 lines of source code to find an error.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #2
    Senior Coder
    Join Date
    Sep 2010
    Posts
    1,997
    Thanks
    15
    Thanked 234 Times in 234 Posts
    Corrected code.
    PHP Code:
    function jsAlert($msg){echo '<script type="text/javascript">alert("'.$msg.'");</script>';} 
    Removed the last double quote near the closing script tag, but wasn't able to edit the OP. It works fine BTW, doesn't mess up you page the way echo can do.
    Welcome to http://www.myphotowizard.net

    where you can edit images, make a photo calendar, add text to images, and do much more.


    When you know what you're doing it's called Engineering, when you don't know, it's called Research and Development. And you can always charge more for Research and Development.

  • #3
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,778
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Another way to do this, if you are running Firebug, is to use the JavaScript console.log() function...maybe it's a little cleaner and less invasive then a bunch of consecutive alert() calls?

    For example:

    PHP Code:
    function jsAlert($msg){echo '<script type="text/javascript">console.log("'.$msg.'");</script>';} 
    See for more info: https://getfirebug.com/logging
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by chump2877 View Post
    Another way to do this, if you are running Firebug, is to use the JavaScript console.log() function...
    You can also do that with Internet Explorer, Chrome, Safari and Opera - all of which have a full debugger built in so that you don't need an extension to handle it the way you do with Firefox.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,641
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by arghyajit View Post
    This wrong code.You will find it on w3schools.com
    The code on w3schools is not so much wrong as out of date because the two guys running the site haven't had time to update it. Anyway that has nothing to do with this thread.

    The PHP code to call JavaScript alert that DrDOS posted is a way to debug PHP by making use of the JavaScript debugging call - alert().
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #6
    0x3
    0x3 is offline
    New Coder
    Join Date
    Sep 2013
    Posts
    37
    Thanks
    0
    Thanked 5 Times in 5 Posts
    When i used to work with PHP this is what i and a buddy of mine found useful.
    http://www.firephp.org/


  •  

    Posting Permissions

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