How to dynamically pass and catch parameters to URL in jsp page
===

I have a JSP page looks like below:

    <html>
	    <head>
    ...
    <script type="text/javascript">
    function toggleChart(chartName) {
				if (document.getElementById("differentIDsHere")) {
				changing different charts
				}
    ...
    function downloadPDF() {
              window.open("<%=response.encodeRedirectURL(" open a new window, reload the same page and print it as pdf");
            }
    ...
    <a id="differentIDsHere" href="javascript:toggleChart_Hits('differentIDsHere');" >Different chart descriptions</a> 

As you can see, when we click different links, the page will display different charts, it works good. But the thing is when I try to call downloadPDF function and open a new window for printing, no matter which link I chose and which chart was displaying before, the new window always shows the default link and chart. 

I tried to create a variation like:

    <script type="text/javascript">
    var currentchart;
    ....
    function toggleChart(chartName) {
    currentchart = chartName; ... }

and want to pass currentchart to the url for opening new window. But I always get a error say cannot find the symbol for currentchart in that url.

Appreciate any advise and thank you all. 
