wood burning stoves*
The moose likes JSP and the fly likes Dynamic adding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Dynamic adding " Watch "Dynamic adding " New topic
Author

Dynamic adding

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
Hi All,
I have a page in JSP which has got 2 button Add and Cancel.
and existing 5 text box when I click on Add button it should add the
6th text box below the 5th text box.
Any idea
Regards,
aakash
Alona Samardin
Greenhorn

Joined: Feb 16, 2003
Posts: 4
What the problem? You can put your textboxes in table one <td> for each textbox when 5 textboxes have "visibility = visible" and the last one has "hidden" until Add button pressed.
For this you don't ever need JSP it's the client side (JavaScript) solution.
Another JS solution may be if you want to create new Textbox for each button pressing.
Here also just client side solution may be used:
you can append to innerHTML of <DIV> or <TD> element
your new textbox html string.


[ February 17, 2003: Message edited by: Alona Samardin ]
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 230

Client side scripting may not a suitable solution here as we do not know "how many" text boxes could be added by the user and for this scripting because these text boxes must pre-exist on the HTML.
One of the ways could well be to render this information to the JSP through a query string (MyJsp?howManyMore=4). If the query string value is null we show the original page (with requsite 5 text boxes). As "Add' is clicked we call the same JSP and give it the information as to how many text boxes are to be appended.
I do not know the application of this JSP but a good solution may be - providing a drop-down list of "how-many-more-text-boxes" which the user could select and can add straightaway by clicking on "add". We can always get this information using request.getParameter(..). The resulting page will create the text boxes inside a loop with 5+number_of_text_boxes iterations.
Hope this helps
[ February 17, 2003: Message edited by: Debashish Chakrabarty ]

Debashish
SCJP2, SCWCD 1.4, PMP, ITIL Foundation
aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
I cannot predefine the no of text box in my html and on clicking ADD button
it should add dynamically one textbox.
I am not allowed to define in a list box the no of textbox to be added.
Is there any other way around.
Regards,
aakash
Debashish Chakrabarty
Ranch Hand

Joined: May 14, 2002
Posts: 230

If you go through my post again you will see that apart from suggesting "predefining number of text boxes" I also suggested passing the information through query string. Say you call the page "MyJsp.jsp?howmany=1", get the query string value and increment it by 1 and the next time "Add" is clicked pass the query string as this incremented value and so on. The value passed on as the query string will tell you how many "additional" text boxes you need to generate below your original five. When yr page is called for the very first time this valye will be null.
Hope this helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic adding