javascript (trying to copy windows.location without success)
<p>This seems like I've fallen down the rabbit hole and I imagine there's a simpler overall strategy, but here I am. </p>

<p>I want to allow users to sort a given set of results AFTER they've already filtered those results.  I want to keep the original filters in place while adding a new one (sort).  I wanted to avoid having to create hidden inputs with the original filters and then submit the form via a click event handler on the sort links. </p>

<p>What I tried to do instead was read the window.location and concatanate the GET parameters with my new sort parameter.  It worked, except that it kept concatanating with each sort click.  I only want one sort variable added per click.  I tried a regex solution and it's not working.  It keeps changing the windows.location variable and redirecting the page. </p>

<p>I'm new to js and I don't know how to deepcopy strings...or the equivalent.  How can I solve this issue? I'm also new to js regex, so pardon my naivety</p>

<pre><code>   $('div#sort ul a').each(function(){
    var currentPath=window.location;
    currentPath=currentPath.replace(/sort=\w+$/,'sort='+$(this).attr('data-sort'));
    $(this).attr('href',currentPath)
</code></pre>
