wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Can Javascript remeber previous values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Can Javascript remeber previous values" Watch "Can Javascript remeber previous values" New topic
Author

Can Javascript remeber previous values

Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 61456
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jetendra Ivaturi
Ranch Hand

Joined: Feb 08, 2007
Posts: 159
check if getHistroy() method could help


SCJP 1.4 & 1.5, SCWCD 1.5. Learn and Let Learn.
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can Javascript remeber previous values