+ Reply to Thread
Results 1 to 3 of 3

Thread: Get querystring javascript.

  1. #1
    gaptrast's Avatar
    gaptrast is offline x10 Sophmore gaptrast is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    117

    Get querystring javascript.

    Hello,

    How to get the query string in javascript?

    Like this:

    Code:
    
    
    <script type="text/javascript">
    function getp(){
    var p = ????GET P????
    document.write('this is ' + p);
    }
    </script>
    
    <div onclick="getp()">Click to show p</div>
    If this website was www.example.com/index.php?p=fun then 'This is fun' had showed up..


    How can I get this work?
    LOOK RIGHT
    LOOK DOWN
    Questions you never knew you wanted answered - http://Wonderabout.info
    [New site!] Collection of fun computer pranks! - http://thefakevirus.com

  2. #2
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Get querystring javascript.

    First step. To find the full URL of the page, use document.location
    HTML Code:
    <html>
    <head><title>Test</title>
    
    function qstring(){
       var q = document.location ;
       alert( q );
    }
    </script>
    <body>
    
    <button onclick='qstring();' >Query String</button>
    </body>
    </html>
    
    Now, you have to figure out how to get the query string from the URL.
    Nothing is always absolutely so.

  3. #3
    essellar's Avatar
    essellar is offline Community Advocate essellar has a spectacular aura about
    Join Date
    Feb 2010
    Location
    Toronto, Ontario, CA
    Posts
    1,153

    Re: Get querystring javascript.

    The query string lives at window.location.search. That being said, there's a neat little function I posted over at Stack Overflow that will probably save you a lot of work. Let me know if you have any questions about it.
    “Beware of bugs in the above code; I have only proved it correct, not tried it.” --Donald Knuth
    "It was as if its architects were given a perfectly good hammer and gleefully replied, 'neat! With this hammer, we can build a tool that can pound in nails.'" -- Alex Papadimoulis (on TheDailyWTF.com)

+ Reply to Thread

Similar Threads

  1. download page querystring
    By gaptrast in forum Programming Help
    Replies: 8
    Last Post: 09-17-2010, 07:59 AM
  2. javascript
    By rick8028 in forum Scripts & 3rd Party Apps
    Replies: 6
    Last Post: 05-31-2009, 12:28 PM
  3. javascript and external javascript files problem
    By delon in forum Programming Help
    Replies: 6
    Last Post: 04-27-2008, 12:41 AM
  4. JavaScript Ads
    By picasa in forum Programming Help
    Replies: 0
    Last Post: 03-22-2008, 05:16 PM
  5. Need Javascript Help
    By coolv1994 in forum Programming Help
    Replies: 6
    Last Post: 03-18-2008, 07:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers