• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can Javascript remeber previous values

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check if getHistroy() method could help
 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic