To generate a page, I use the following code:
<%List<String> someList = new ArrayList<String>();
someList = SQL();%>
<select id=Select>
<% for (int i =0; i < someList.size(); i++) { %>
<option value=<%= someList.get(i) %>><%= someList.get(i) %></option>
<%} %>
</select>
<button type="button" onclick="updateParagraph()">Update Paragraph!</button>
The above code is executed on the server using JSP. However, now I want the following code to run on the client side.
var counter=0;
function updateParagraph()
{
var x = document.getElementById("paragraph"+counter);
var y = document.getElementById("Select").value;
if (counter < 5)
{
x.innerHTML = y;
counter++
}
}
The code works as intended, but the issue is that I don't want to limit the number of paragraph changes to just 5. I need advice on how to determine the number of options in the <select> element. Depending on the output of the SQL() function, there could be anywhere from 5 to 55 options in the select dropdown.
I hope this clarifies my question.