I have an array of values that I want to pass in as a parameter to a Javascript function. For instance, something like:
<% ArrayList<String> arr = NodeUtil.getValues(); %>
<input type="button" name="submit" value="Add" onClick="addTextBox('<%= all values in arr %>')"/>
I’m trying to dynamically add textboxes to a div. Their names need to correspond to the values in the array. That is, in my js function I have a loop for:
newdiv.innerHTML = "<input type=\"text\" style=\"width: 235px\" name=\+each value in arr +"\" />
Is this possible?
The solution in the linked question is good, but if you don’t want an external library:
This is ustil JSTL and EL, which is the recommended way of writing code in JSP. If you want to write scriptlets, it will be very similar – with a
for (String item : arr) { .. }