Javascript: working with query string
<p>I'm trying to write a Javascript function to get the query string of the browser and allow a new key/value to be passed to the function. If the key exists, I need to replace the value. Since I've spent the last 3.5 hours on this, I haven't yet gotten around to the replacing part.</p>

<p>So far, I'm using the answer here: <a href="http://stackoverflow.com/questions/2907482/getting-querystring-by-javascript">getting QueryString by Javascript</a> to get the query string. However, it doesn't appear to work... The URL I was testing with was: <a href="http://www.site.com/poo?drwho=tombaker&amp;companion=k9" rel="nofollow">http://www.site.com/poo?drwho=tombaker&amp;companion=k9</a></p>

<pre><code>  var assoc  = {}; 
  var decode = function (s) { return decodeURIComponent(s.replace(/\+/g, " ")); }; 
  var queryString = location.search.substring(1);  
  var keyValues = queryString.split('&amp;');  

  for(var i in keyValues) {  
     var key = keyValues[i].split('=');  
     assoc[decode(key[0])] = decode(key[1]);  
  }  

  if(assoc["dr"] === undefined ) { 
     // not found. todo: replace
  } 
</code></pre>

<p>I'd really appricate any help! Is there any simpler way of doing this using JQuery?</p>
