-1

I want to compare a javascript variable with a jsp variable. How can I do this?

 function verify_details()
   {
    var resourceId=document.getElementById("res").value;'
    <%! String rId;%>
    <%
    for(int i=0;i<l.size();i++)
    {
      rId=l.get(i).toString();
       System.out.println("Elements Are:"+rid);
    %>
       if(resourceId==rId)
        alert("Alloted");
       else
           alert("Not Alloted");  

   <%}%>

   }
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 1
    possible duplicate of [How to access list from JSP in Javascript?](http://stackoverflow.com/questions/6567762/how-to-access-list-from-jsp-in-javascript) – Harry Joy Jul 04 '11 at 06:48

2 Answers2

1

You shouldn't be doing this in the first place. See this.

If you really want to, make a new JSP with this code in it, pass the variable you want to compare as a parameter (call that page with AJAX) and get the result.

But, that's overly complicated and this situation should really never occur in code that is well structured.

Community
  • 1
  • 1
Dhaivat Pandya
  • 6,499
  • 4
  • 29
  • 43
0

Use some control like 'hidden' or any other. Its value will be accessible in both javascript and jsp.

H.Muster
  • 9,297
  • 1
  • 35
  • 46
MLS
  • 885
  • 1
  • 9
  • 16