Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can Javascript remeber previous values

 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just added some Javascripts to keep my <div> elements hidden until the user chooses a value under <select><option>...This way I do not have to submit the form and then redisplay to display the choosen element.

However. When the new form is then submitted the page is redisplayed with the results and the div element is again hidden.

Initially all <div> fields are to be hidden, but I want to show the last choosen filed after a form submit(technically when the form reloads again the javascript treats it as an initial load and all is hidden).

I cannot set the divFieldID.className="show"; before a javascript method is called in a form <select onchange="myFunction();">.

I have a JSP variable I can access to find out it the user has choosen a form in the <select><option>...

Can I fix this with Javascript, or do I have to abandon it and revert to my old JSP if-else with alot if submit
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is called you have to come up with a solution that shows the div. Easy solution is to have the serverside code set the values if it knows it should be displayed. So you spit out the correct HTML based on the situation you are in.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sverre Moe:
Can I fix this with Javascript, or do I have to abandon it and revert to my old JSP if-else with alot if submit


Why would you do something in JavaScript that you can handle on the server? Always do what you can on the server to keep the page sent to the browser as simple as possible.
 
Jetendra Ivaturi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check if getHistroy() method could help
 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:


Why would you do something in JavaScript that you can handle on the server? Always do what you can on the server to keep the page sent to the browser as simple as possible.


I was just thinking about avoiding to submit and go through the servlet again only to display a selected form. There is no needed processing in the servlet before that form is submitted.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic