SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you access query string variables?

    Hello,

    I have found many there are many ways to retrieve a querystring variable, and people have posted many functions out there. What would be the correct way to go?


  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by rhgiant View Post
    Hello,

    I have found many there are many ways to retrieve a querystring variable, and people have posted many functions out there. What would be the correct way to go?

    It depends.

    The querystring is available via the window.location object, as window.location.search
    Everything else stems from that.

    The question mark at the start is of no use to you.
    The terms are divided by ampersands.
    Each term is divided by the equals sign.

    So it's up to you to decide whether you want to split things up and interpret them accordingly, or to use a small library to do the job for you.

    The following seems to provide good details about this: Javascript Madness: Query String Parsing
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot

    How would you use the JMadness library? I'm trying to do this:

    Code:
    if(qs.value('test') == true) {
    	alert('found');
    	}

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,702
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by rhgiant View Post
    Thanks a lot

    How would you use the JMadness library? I'm trying to do this:

    Code:
    if(qs.value('test') == true) {
    	alert('found');
    	}
    Like this:

    Code javascript:
    var qs = new querystring();
    if (qs.value('foo') === 'bar') {
        ...
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2011
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •