#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    5
    Rep Power
    0

    How to transfer a Java value to Javascript and loop through to get the values?


    I am trying to loop through a java array using javascript and store the value in the textbox named txtAAESNo. But i am geting the following error:
    value "i" cannot be resolved.

    Pls help!


    Code:
    function hello()
    {			
    
      var i;
    	for( i = 0; i < <%=arrAccSec.length%>; i++)
    		{
    	document.getElementById('txtAAESNo').value=<%=arrAAFS[i][1] %>;
    				
    			
    		}
    			
    	
    }
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    101
    Rep Power
    26
    You're displaying a basic disconnect in understanding the separation between client-side javascript and, in this case, JSP. You instantiated a variable "i" in some javascript, then expect that variable to exist when the JSP is compiled, which is impossible. In this example, the loop should be implemented in the JSP.
    Code:
    <% for (int i=0; i<arrAccSec.length; i++) { %>
            document.getElementById('txtAAESNo').value=<%=arrAAFS[i][1] %>;
    <% } %>
    (JSP particulars may not be correct here, I'm just guessing)

    Also I notice that you're using two different list variable names in JSP, "arrAccSec" and "arrAAFS". Seems error-prone to iterate arrAAFS according to the length of arrAccSec. But what do I know.

    Aside from that, the example itself seems nonsensical - why are you iterating a list and overwriting the value of a text box with each list item? The result will be that the text box contains the last item in the list. What does that accomplish?

    Comments on this post

    • Kravvitz agrees
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    hi dear..
    i am the expert in languages.java is my favorite.now contact with me.i solve your problem.

IMN logo majestic logo threadwatch logo seochat tools logo