Associate
- Joined
- 8 Apr 2004
- Posts
- 2,053
Hi, I'm trying to use a for-loop to loop some repetitive code I have in this JSP file. This is what it currently is as how I want it to look:
<input type="text" name="cat_name" size="20" maxlength="50" value="Art" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat1" value="replace" /> Replace 
<input type="radio" name="cat1" value="remove" /> Remove<br />
<input type="text" name="cat_name" size="20" maxlength="50" value="Food/Drink" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat2" value="replace" /> Replace 
<input type="radio" name="cat2" value="remove" /> Remove<br />
<input type="text" name="cat_name" size="20" maxlength="50" value="History" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat3" value="replace" /> Replace 
<input type="radio" name="cat3" value="remove" /> Remove<br />
<input type="text" name="cat_name" size="20" maxlength="50" value="Markets" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat4" value="replace" /> Replace 
<input type="radio" name="cat4" value="remove" /> Remove<br />
This creates 4 lines, each with a textbox and 2 radio buttons beside it. The only thing that differs at the moment is the value in the textbox.
What I'm trying to do is put the textbox values into an array and then use a for-loop (going up until array.length obviously) to repeat the repetitive code there. I read that within the for-loop block, you had to use a JSP-end tag, write your XHTML code and then use a JSP-open tag again. However, it doesn't seem to work. I even tried something simple like printing out 'Hello' and it only writes it out once, not repeating it array.length times.
Anyone have any idea? How should I write a for-loop properly for the above code? If you need me to be a bit more specific, I'll be happy to provide more. Regards
<input type="text" name="cat_name" size="20" maxlength="50" value="Art" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat1" value="replace" /> Replace 
<input type="radio" name="cat1" value="remove" /> Remove<br />
<input type="text" name="cat_name" size="20" maxlength="50" value="Food/Drink" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat2" value="replace" /> Replace 
<input type="radio" name="cat2" value="remove" /> Remove<br />
<input type="text" name="cat_name" size="20" maxlength="50" value="History" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat3" value="replace" /> Replace 
<input type="radio" name="cat3" value="remove" /> Remove<br />
<input type="text" name="cat_name" size="20" maxlength="50" value="Markets" class="editbox" title="Edit Category" /> 
<input type="radio" name="cat4" value="replace" /> Replace 
<input type="radio" name="cat4" value="remove" /> Remove<br />
This creates 4 lines, each with a textbox and 2 radio buttons beside it. The only thing that differs at the moment is the value in the textbox.
What I'm trying to do is put the textbox values into an array and then use a for-loop (going up until array.length obviously) to repeat the repetitive code there. I read that within the for-loop block, you had to use a JSP-end tag, write your XHTML code and then use a JSP-open tag again. However, it doesn't seem to work. I even tried something simple like printing out 'Hello' and it only writes it out once, not repeating it array.length times.
Anyone have any idea? How should I write a for-loop properly for the above code? If you need me to be a bit more specific, I'll be happy to provide more. Regards