SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Jan 2003
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calling javascript from PHP

    I have a PHP function as follows:
    function alert($message)
    {
    echo "<script language = javascript>
    alert('$message');
    </script>";
    }

    which works properly, but

    What I want is another function of the form:
    function alertAndGo($message, $url)
    {
    echo "<script language = javascript>
    window.location('$url');
    alert('$message');
    </script>";
    }

    that is called as follows:
    alertAndGo("blah blah", 'file_name.php');

    I have tried this but can't get it to work,
    any help would be appreciated!

  2. #2
    Mlle. Ledoyen silver trophy seanf's Avatar
    Join Date
    Jan 2001
    Location
    UK
    Posts
    7,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JavaScript issue. JS ain't my thing, so I've moved it here as somebody might suggest using something other than location.replace

    PHP Code:
    <?php

    function alertAndGo($message$url)
    {
    echo 
    "<script language = javascript>
    alert('
    $message');
    location.replace('
    $url');
    </script>"
    ;
    }

    ?>
    Sean
    Harry Potter

    -- You lived inside my world so softly
    -- Protected only by the kindness of your nature


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
  •