JavaScript Code

Retrieve QueryString Parameters with JavaScript

Sometimes you need to retrieve a querystring parameter or two for use in a JavaScript function. Or you are stuck in a static environment, you only have HTML to work with, and you need to pre-populate a form. This handy function will enable you to do that.

function Querystring(qs) { // optionally querystring to parse
this.params = new Object()
this.get=Querystring_get

if (qs == null)
qs=location.search.substring(1,location.search.length)

if (qs.length == 0) return

// Turn '+' back to ' '
qs = qs.replace(/\+/g, ' ')
var args = qs.split('&') // parse out name/value pairs separated via &

// split out each name=value pair
for (var i=0;i

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image