title: Javascript Url Parameter parsing
body: <p>So, I really need some help. I've done extensive searches, and some of the solutions I've found are great but aren't working for me, so here goes...</p>
  
  <p>When someone comes to my site, they are going to click on a link which will pass a URL to "recipes.html"... For Example, if they clicked on "Ancho Chile Sauce", the URL would be:</p>
  
  <p>blahblahblah.com/recipes.html?r=Ancho-Chile-Sauce</p>
  
  <p>This parameter is actually the name of a JPEG in the folder "Recipes", of course with the ".jpg" extension</p>
  
  <p>I need to take this parameter into a string and add "Recipes/" before it and ".jpg" after it, and then alter the source of an image tag in my html document to display the new dynamically called recipe image.</p>
  
  <p>I thought I'd done this, but nothing seems to be working. There's obviously something I'm doing wrong in my Javascript, because my markup works fine and the url with parameter is getting passed. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Recipes&lt;/title&gt;
  &lt;link href="mobi-styles.css" rel="stylesheet" /&gt;
  &lt;script type="text/javascript"&gt;
  function getParam ( sname )
  {
    var params = location.search.substr(location.search.indexOf("?")+1);
    var sval = "";
    params = params.split("&amp;");
      // split param and value into individual pieces
      for (var i=0; i&lt;params.length; i++)
         {
           temp = params[i].split("=");
           if ( [temp[0]] == sname ) { sval = temp[1]; }
         }
    return sval;
  }
  window.onload = changePic();
  var param = getParam("r");
  var recipeName = "Recipes/"+param+".jpg";
  function changePic() {
  document.getElementById("recipe").src=recipeName;
  }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &lt;img class"resizer" id="recipe" src="" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Please help! Me love you long time!</p>