Javascript Associative Parser for Querystrings - ΩJr. Software Articles and Products

This information lives on a web page hosted at the following web address: 'https://www.omegajunior.net/code/'.

A.E.Veltstra
7 Sep. 2003

Transform the Querystring from a web address into a named or associative 'array' for easy choice retrieval via javascript. Here's how.

A word from a sponsor:


Imagine having a form on one web page, and a database script on another. You want to retrieve the form input and use it in your database script, or at least show that you received them in good order. How do you do that?

Now let's try again, but this time without asp, php, c#, perl, and what-have-you. Your client has a server that doesn't allow any server-side code whatsoever. Then what?

Right, you build a javascript solution. I built a querystring object in client-side javascript that behaves like a named or associative array. Just like similar objects in server-side javascript, vbscript (asp), perl, php, python, and the likes.

Example below. A form with some choices and inputs. Enter something and hit OK. What you entered should appear below it.

And how does that work?
You copy the querystring.js to your own web server, and to your web page you add a reference to that script:
<script src="querystring.js"></script>

Then you retrieve the querystring parameters from the web address to your page as follows:

if (QueryString) { if (QueryString.length) {
if ( QueryString.hasOwnProperty("variable") ) {
var value = QueryString[ "variable" ];
window.alert( value );
}
} }



Try it:

Guinness?

Alcohol?

Need problem solving?

Talk to me. Let's meet for coffee or over lunch. Mail me at “code at omegajunior dot net”.