SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to echo() javascript alert(); ?

    Hi, what I want is to execute some javascript code with echo(); basicallly see below what I want

    Code PHP:
    echo "<script>javascript: alert('test msgbox')></script>";

    the above code doesnt work, how to evaluate javascript code in echo() ?

    please help..

    thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also tried the script type..

    <script type="text/javascript">

    but it does not execure my javascript functions..

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're trying to use javascript like you would through the URL bar.

    Remove the 'javascript:':
    PHP Code:
    <?php
    echo '<script type="text/javascript">alert("hello!");</script>';
    ?>
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, it worked, honestly I tried this earlier, but that didnt work the only difference was that I was trying in double questions with \" but its working in single quotes. thanks

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Save yourself some future headaches when writing JS inside PHP, look at using the PHP heredoc syntax when possible.

    http://www.hudzilla.org/phpbook/read.php/2_6_3

  6. #6
    SitePoint Enthusiast invalidsyntax's Avatar
    Join Date
    Feb 2008
    Location
    CALI
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set as resolved
    Python Noob


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
  •