Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add checkboxes dynamically using a JSP

I have a string variable which is assigned with certain no. of labels. For eg, String var ="ChkBox1,ChkBox2,ChkBox3" in a JSP.

Now, my requirement is, I have to extract the checks out of the string and store them in an array and dynamically add checkboxes(3 checkboxes as per above example) to the page by running a for loop (based on no. of elements in the array) and display them.

If the variable is later changed to String var = "ChkBox1,ChkBox2,ChkBox3,ChkBox4", the webpage should now contain 4 checkboxes. I am relatively new to JSP. Please help me out on how to design this logic.

PS:I already implemented the extraction of checkBoxes from string and formed an array. I need assistance on how to use a for loop to add checkboxes dynamically

like image 285
Surya Chandra Avatar asked Mar 19 '26 15:03

Surya Chandra


1 Answers

<%
for(int i = 0; i < array.length; i++)
{
%>
<input type="checkbox" name="<%= array[i]%>">
<br/>
<%
}
%>
like image 199
jsshah Avatar answered Mar 21 '26 05:03

jsshah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!