Calling a Java function with a JavaScript variable inside a JavaScript function
<p>I need help. I need to call a Java function "getLocCountByWhId()" in a Java class; this Java function is being called within a JavaScript in a for-loop. I need to pass in a JavaScript variable as a parameter into this Java function "getLocCountByWhId()". I have been struggling for a week and reading numerous website to get some guidelines but I have not been able to resolve the problem. Thank you in advance for your help. The code is listing below:</p>

<pre><code>&lt;script language="JavaScript"&gt;
&lt;!--
function onCreatePO()
{
    &lt;%long jspAllocId = alloc.getId();%&gt;;
    var recItemId = ""; // Local variable for item id.
    var recWhId = ""; // Local variable for warehouse id.                           

    for (var i=0, j=document.what_if_summary.elements.length; i&lt;j; i++)
    {      
       var recStr = document.what_if_summary.elements[i].value; 
       var splitStr = new Array(); 
       splitStr = recStr.split('^');
       recItemId = splitStr[1]; // Get the field value for Item_ID.
       recWhId = splitStr[2]; // Get the field value for Warehouse_ID.

// Get a database connection with global 'conn' object and retrieve store count.
       &lt;%AfsGetVDSCountByWarehouseBean.setConnection(conn);%&gt;; 

// The below assignment from JavaScript variable to JSP variable do not work 
// because of a second JavaScript tag. How can I get around this ?

//&lt;% String jspItemId = "&lt;script&gt;document.writeln(recItemId)&lt;/script&gt;"; %&gt;
//&lt;% String jspWhId = "&lt;script&gt;document.writeln(recWhId)&lt;/script&gt;"; %&gt;

   currentStoreCount = &lt;%= AfsGetVDSCountByWarehouseBean.getLocCountByWhId(jspAllocId, jspItemId, jspWhId)%&gt;;
   }
}

//--&gt;
&lt;/script&gt;

// I get this example of assigning Javascript to JSP variable but I got double tag problem.
&lt;script&gt;
var v="Roseindia";
&lt;/script&gt;
&lt;% String st="&lt;script&gt;document.writeln(v)&lt;/script&gt;";
out.println("value="+st); %&gt;
</code></pre>
