Featured Post

Field Marshal Sam Manekshaw on leadership

Field Marshal Sam Manekshaw on leadership I had a chance to read this article recently and just loved the way he describes leadership...

Monday, May 22, 2006

Dynamically adding text box in JSP

You can dynamically add text box on runtime when you click on add Button.
Assume you need to create a text box and on run time when you click on add button.
Create a for loop around the text box and on click of the add button increment the for loop condition variable.
for Example.

for(int i=0;i<=count;i++){
text box code.....
}

Add Button.(onClick="javascript:reloadPage();");

when the add button is clicked in the javascript code resubmit to the page.
On top of the page in scriptlet have a variable called count initialise to 1.
for Example: int count = 1;
When the page reloads increment the count with 1. like count++;
Now the count will be 2 and in forloop 2 text box will be created.
If u need the value of the 1st text box to retain. Take that value in request and reassign to the text box.
For text box have the variable as textbox<%=i%>
So each time the loop comes it will create dynamic text box.

Google Custom search

Custom Search