title: Outputting URL Variables to a string using Javascript and then use the string in an iframe
body: <p>So I'm  trying to do two things, first is outputting url variables into a javascript string and then use that string within an iframe.</p>
  
  <p>The URL is: <a href="https://testurl.com/report.html?name=Jack&amp;zip=rg1&amp;city=Reading" rel="nofollow">https://testurl.com/report.html?name=Jack&amp;zip=rg1&amp;city=Reading</a></p>
  
  <p>The code I have so far is:</p>
  
  <pre><code>&lt;script&gt;
  function GetUrlValue(VarSearch) {
      var SearchString = window.location.search.substring(1);
      var VariableArray = SearchString.split('&amp;');
      for (var i = 0; i &lt; VariableArray.length; i++) {
          var KeyValuePair = VariableArray[i].split('=');
          if (KeyValuePair[0] == VarSearch) {
              return KeyValuePair[1];
  
              var name = GetUrlValue('name');
              var zip = GetUrlValue('zip');
              var city = GetUrlValue('city');
          }
      }
  }
  
  var iframetesting = 'https://testurl.com/report.html?name='+name+'&amp;zip='+zip+'&amp;city='+city+'&amp;country=GB';
  &lt;/script&gt;
  </code></pre>
  
  <p>When I put it  into an alert it says undefined.</p>
  
  <p>Once thats done, I then need to put that into an iframe source.</p>
  
  <pre><code>&lt;iframe src="javascript:myfunction()" width="100%" height="2300px" frameborder="0"&gt;
  
  
  &lt;/iframe&gt;
  </code></pre>
  
  <p>If anyone could help me solve where I am going wrong that would be great.</p>
  
  <p>Thanks</p>