Get URL parameters in JS and embed into a JS function
<p>I have a graph library that I use to plot some data.</p>

<p>This data comes passed as a GET paramater in the URL in the following format: <code>plottedgraph.html?case_id=4&amp;otherparam=blabla</code></p>

<p>Then I have my HTML page where I try to catch that GET param with the GUP function (below) and add it to my JS function as follows: <code>"http://www.url.com/showgraph.do?case_id=" + gup('case_id') + "&amp;status=weighted"</code></p>

<p>This is the whole HTML</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
    &lt;!--[if IE]&gt;
      &lt;script type="text/javascript" src="js/excanvas.js"&gt;&lt;/script&gt;
    &lt;![endif]--&gt;
    &lt;script type="text/javascript" src="js/dygraph-combined.js"&gt;&lt;/script&gt;

    &lt;script type="javascript"&gt;
    function gup( name )
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&amp;]"+name+"=([^&amp;#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }
    &lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div id="graphdiv2" style="width:1800; height:900px;"&gt;&lt;/div&gt;
&lt;script type="text/javascript"&gt;
  g2 = new Dygraph(
    document.getElementById("graphdiv2"),
    "http://www.url.com/showgraph.do?case_id=" + gup('case_id') + "&amp;status=weighted", // path to CSV file
    {
      showRoller: true,
      colors: ["rgb(255,100,100)",
               "rgb(72,61,139)"]
    }          // options
  );
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Unfortunately the JS function doesn't recognize that case_id=4 in this case...</p>

<p>Could you please let me know what am I doing wrong?</p>
