Instead of templating the filter into the dom in the initial response, and then laboriously changing it, why not just template a javascript variable? And then just keep it there. Generally, you're making the DOM and (especially) url do work that could be much better done with js alone.