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 7 of 7
  1. #1
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts

    Sending $string data without a form

    Hi

    I use PHP and have no clue with javascript.
    is there a way of sending $string data to a new page using javascript instead of a form. On the new page I wish to pick up that data with:

    PHP Code:
    $prevpage $_REQUEST['sentdata'];
    echo 
    $prevpage
    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Read http://in2.php.net/session including examples.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts
    I will take that as a no then

  • #4
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    yes there is, it's a technology called AJAX. it's just a long answer for a short problem.

    Code:
    <script type="text/javascript">
    function sendString(sendTo, value){
        var xhr = XMLHttpRequest?(new XMLHttpRequest()):(new ActiveXObject("Microsoft.XMLHttp"));
        xhr.open("get", sendTo + "?sentdata=" + value, true);
        xhr.onreadystatechange = function(){};
        xhr.send("");
    }
    </script>
    add onclick="sendString('url to page to send to', 'string to send');" to whatever button it is that you want to have send the string. this uses the "Get" method of sending information, so you would use $_GET['sentdata'] to get the value of it, but if you change "get" in the function (above) to "post" you can use $_POST['sentdata'] instead.

    Code:
    <html>
    <head>
    ...
    //Script from above goes here
    </head>
    <body ...>
    ...
    <input type="text" id="myString" value="" />
    <input type="button" value="Send" onclick="sendString('mypage.php', document.getElementById('myString').value);" />
    ...
    </body>
    </html>
    would be a simple example of how to use this.
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • Users who have thanked mjlorbet for this post:

    Trinity-Links (03-30-2008)

  • #5
    New Coder
    Join Date
    Mar 2008
    Location
    Leuchars, Scotland, UK
    Posts
    51
    Thanks
    19
    Thanked 0 Times in 0 Posts
    can this work on a hyper link rather than a button?

  • #6
    Regular Coder mjlorbet's Avatar
    Join Date
    Jan 2008
    Location
    Milwaukee, WI
    Posts
    724
    Thanks
    8
    Thanked 96 Times in 95 Posts
    <a href="javascript:void(0)" onclick="...">My link</a>
    just make the contents of onclick with the same from the one on the button
    -Mike
    "Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender

  • Users who have thanked mjlorbet for this post:

    Trinity-Links (03-30-2008)

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    <a href="javascript:void(0)" onclick="...">My link</a>
    Code:
    <a href="#" onclick="...;return false;">My link</a>
    is the proper way.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Trinity-Links (03-30-2008)


  •  

    Posting Permissions

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