Search code examples
javascriptjqueryspringjspjstl

Passing JavaScript variable gives an error


I used to generate a field set when a button is clicked in my application. That field set inputs take attribute of an object. Whenever add button is clicked, I have to generate a field set. Spring bind used for input elements.

I set this newly created object in a list. So, when I'm generating the field set, I have to name it properly which set the object to next element. I tried this and it's not working.

path="subdivisondto.subDevisions[${'+parseInt(countnum)+'}].subDivisonName">

This code comes inside jQuery append method.

I tried with parseInt(countnum). But, it's not working.

subDevisions 

is a list. So, I have to increase the one by one using a variable to set the object to list.


Solution

  • I'm wondering what ${'+parseInt(countnum)+'} is supposed to achieve. Let's assume that parseInt(countnum) converts the string countnum to an integer. So this would give (for example): ${'+1+'}

    That looks like you convert a string to an integer just to get a new string. How about this:

    <%
    String path = "subdivisondto.subDevisions[" + countnum + ".subDivisonName";
    %>
    <... path="<%= path %>">