• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP and Form question  RSS feed

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a form implemented within a jsp page.

Basically, there are the following elements:

Firstname:
Lastname:
email:

Quotes:

I want to implement the following:

Quotes is a html input field as firstname, lastname etc. however i want to enable the user to enter any number of quotes, so next to the input field there should be a button/link where the user can select "add quote".
all the added quotes will then be shown immediately on the same page.
now my question is:
if the user has already filled out firstname, lastname and email and enters a quote, how can it be displayed on the page in the added quotes section WITHOUT refreshing the page and WITHOUT getting rid off the data filled out in the form already?

i hope its clear what i am trying to explain.

any help appreciated..
 
Author and ninkuma
Marshal
Posts: 66350
155
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, as long as the end-user doesn't have JavaScript disabled, this is a fairly common thing to do on the client. If you can't use JavaScript, you'll need to refresh the entire page and restore the previous values.

If you want to discuss the JavaScript approach, let me know and I'll move this to the JavaScript forum.
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, please. How will that be done using JavaScript?
And also how would it be solved without JavaScript?

I am actually interested in both solutions.

thanks
[ November 20, 2008: Message edited by: Viv Singh ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66350
155
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The non-Javascript solution is: use the value attributes of the for elements to set their values when the page is re-displayed.

For the JavaScript solution, I've moved this to the appropriate forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66350
155
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To create new elements in the DOM, explore the DOM API or use innerHTML to manipulate the DOM. Of course, you'll need to deal with event handling to know when things get clicked.

I'd highly recommend the adoption of a library like jQuery which makes both event handling and DOM manipulation much easier than doing it "by hand" and without having to worry about IE's proprietary nonsense.
 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, thanks for your help bear.

for the non javascript-version could you please give me an example.

the thing is that all the quotes that will be entered should be stored somewhere as they will be needed in a servlet that stores the data in a database.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66350
155
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you submit the form, any dynamically created elements will also be submitted, and so your servlet won't have to do anything special.

A simple example of creating an element using the innerHTML mechanism could be:
Obviously, more complex HTML will be more wordy, but you get the idea.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!