Replace hard coded values in an array with values from another array with JavaScript?
<p>I have a sharepoint site and want to create a script for links with querystring values that are not hard coded so I can use it on several sites without having to alter it. The HTML is a mess and I can't alter it.</p>

<p>I have some charts with links to a page with more details. On the page with charts I have some filters and when a user selects one of them the page reloads and the url then contains a querystring value.</p>

<p>With javascript I want the charts to get links depending on the querystring value so the page with more details reflects what the user selected in the filter.</p>

<p>The links from the charts looks something like
<a href="http://mysite.com/details.aspx?filter=train" rel="nofollow">http://mysite.com/details.aspx?filter=train</a></p>

<p>To get this link I have a script that creates them with this</p>

<pre><code>goPage[0]= baseURL + filter[queryString];
goPage[1]= baseURL + filter[queryString];
</code></pre>

<p>I know the possible querystring values already (max 10) so I hard coded them in an array</p>

<pre><code>filter[1] = 'road';
filter[2] = 'train';
filter[4] = 'horse';
</code></pre>

<p>So my question is, how do I do this if I don't know the querystring values on beforehand?</p>

<p>The links are dynamically added in the html document and I get all possible querystring values with:</p>

<pre><code>  var businessUnitID = new Array();
  $('.table404').children().children().each(function(){
  var link = ($(this).find('a').attr('href'));
  var startIndex = link.indexOf(",'");
  var endIndex = link.indexOf("');");
  if ( startIndex &gt;= 0 &amp;&amp; endIndex &gt;= 0 ) {
      var linkID = link.substring( startIndex+2, endIndex );
  businessUnitID.push(linkID);
  }
  alert(businessUnitID);
  });
</code></pre>

<p>Any ideas?
Thanks in advance</p>

<p>edit: updated the question with more information</p>

<p>to get the queryString I use the following code:</p>

<p>//Get the filter ID from the querystring</p>

<pre><code>function gup( filter )
{
  filter = filter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&amp;]"+filter+"=([^&amp;#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

var queryString = gup("SelectedID");
</code></pre>

<p>Also, instead of having road, train etc hard coded I get it with</p>

<pre><code>  var businessUnitName = new Array();
  $('.table404').children().children().each(function(){
  var linkText = ($(this).find('a').text());
  businessUnitName.push(linkText);
  //alert(businessUnitName);
  });
</code></pre>

<p>So instead of having:</p>

<pre><code>  var filter = new Array();
  filter[1] = businessUnitName[1];
  filter[2] = businessUnitName[2];
  filter[4] = businessUnitName[3];
  filter[5] = businessUnitName[4];
  filter[7] = businessUnitName[5];
  filter[9] = businessUnitName[6];
  filter[10] = businessUnitName[7];
  filter[11] = businessUnitName[8];
  filter[14] = businessUnitName[9];
  filter[15] = businessUnitName[10];
</code></pre>

<p>I want to, if for example the querystring value is the third value in the businessUnitID array, set filter to businessUnitName[3];</p>

<p>I hope I make myself clear here, please ask if you have any further questions.</p>
