SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Apr 2013
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Write javascript in php using echo.

    Hi,

    I want to write following javascript in my php script at server side.

    Code:
    <script language="javascript" type="text/javascript">
    alert("Your message has been send successfully");
    window.location.href="My-page.php?id=<?=$id?>";
    </script>
    I try following but not working

    Code:
    <?php
    
    echo "<script language='javascript' type='text/javascript'>";
    echo "alert('Your message has been send successfully');";
    echo "window.location.href='My-page.php?id=".$id;
    echo "</script>";
    
    ?>
    Any idea?

    -Thanks

  2. #2
    SitePoint Guru glenngould's Avatar
    Join Date
    Nov 2005
    Posts
    661
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What happens when you load the page? It should work. You named your page with ".php" right?
    Tweep List adds an avatar menu to Twitter (open source)
    Word Stats shows your most used words on Twitter

  3. #3
    SitePoint Zealot
    Join Date
    Apr 2013
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool

    Now it is working.


    Code:
    echo "<script language='javascript' type='text/javascript'>";
    echo "alert('Your message has been send successfully');";
    echo "</script>";
    
    $URL="page.php";
    echo "<script>location.href='$URL'</script>";


Tags for this Thread

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
  •