• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retaining javascript values in jsp

 
Prashant Langade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"?
 
Prashant Langade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you submit the request to the same JSP? When you make an AJAX call then (on which condition)?
 
Prashant Langade
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.. i am making a request to same jsp..
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic