wood burning stoves 2.0*
The moose likes Servlets and the fly likes Retaining javascript values in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Retaining javascript values in jsp" Watch "Retaining javascript values in jsp" New topic
Author

Retaining javascript values in jsp

Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Hi

I have a dropdown box added using javascript in JSP.

But when i do some operation on the jsp like add/edit/delete.the form gets submitted,so the dropdown values gets vanished as
those are added at clientside by javascript.

So i want to access those list of dropdown values in the servlet so that i can keep them in session and can retain them on the jsp.


Can any one please help me?

Prashant
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Prashant Langade wrote:But when i do some operation on the jsp like add/edit/delete.the form gets submitted,so the dropdown values gets vanished as
those are added at clientside by javascript.

I'm not that sure what you are saying, Is it that you are not able to retrieve the user selected value of the select list in the servlet once the request is form is submitted? If so, can you show us how you do that in the code?
So i want to access those list of dropdown values in the servlet so that i can keep them in session and can retain them on the jsp.

What you meant by "retain them on the jsp"?

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Hi Vijitha

Thanks for your response.

Actually i have a jsp page where in i have created the dropdwon box using javascript
here is the code



Here is addOption function

-

Now when the dropdwon gets populated with the values from Ajax call..i dont have any issue
but when i do some opernation like add/edit/delete (where in the form gets submitted to the server,so the dropdown added with javascript code gets vanishes as it is added in client side)

But i want these dropdown to be there after submission of the form too..

Prashant
Ochi Elty
Greenhorn

Joined: May 07, 2010
Posts: 15
Hi,

I suggest the ff:

Before showing up the JSP with the drop down list, you trigger a servlet right? You can put all the values of the dropdown list in session, forward to your jsp page, capture the session data in jsp, loop on the list while populating the SELECT html element.

On your servlet prior to displaying the jsp, you can have this code.



then forward to your jsp page

On your jsp page, you can have this code to populate you drop down list:



This code won't use javascript to populate your drop down list.


Hope this helps.




Why most of the people are so cruel? Most of the time, I have to be the same.
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Ok first part is clear.
But i want these dropdown to be there after submission of the form too..

Where you need this dropdown? Can you elaborate?
You need every values populated in to the select list retrieved in the servlet once the form submitted? Or the selected value only? (If I get it correctly )
Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Hi Vijitha

I want all the values in the dropdown to be there in the same JSP after the form submission.

Prashant
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Looks like you submit the request to the same JSP? When you make an AJAX call then (on which condition)?
Prashant Langade
Ranch Hand

Joined: Jul 01, 2009
Posts: 71
Yes.. i am making a request to same jsp..
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

OK, If you want the values to be loaded (through AJAX) first time for that particular user and keep them across the user's session why don't you load them at the beginning (perhaps at login, maybe)?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Retaining javascript values in jsp
 
Similar Threads
dropdown selection in Struts2
Question on RELOAD of JSP page AFTER facesMessage fixed
mouse hover on multiselect dropdown
mouse hover on multiselect dropdown
list box problem