File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Preserving State Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of Practical Unit Testing with TestNG and Mockito this week in the Testing forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply Bookmark "Preserving State" Watch "Preserving State" New topic
Author

Preserving State

Rob Hunter
Ranch Hand

Joined: Apr 09, 2002
Posts: 764
Hi All,
Heres a problem I'm having. I have 2 variables on a page, both hidden. Ones called state1 and ones called state2. Upon loading the page these 2 hidden fields are set to "NOCHANGE". When the user clicks on the submit button or a link on the page the state2 should change to "CHANGED", using a javascript onclick statement. In the javascript, I do this :
document.result.state2.value = "CHANGED";
(result is the form's name). After that I put in an alert button, it says that the value has indeed changed to "CHANGED" but viewing the source code still has "NOCHANGE" in there and coming back to the page it says that the hidden field is still "NOCHANGED". Why is this? And is there a way of changing the value to what I want (i.e. CHANGED so as when I return to the page)?
The reason I do this is because first in the page is the way it should be. Clicking on submit or a link should make them (the hidden fields) different so that the page knows when the user has returned to the page using the Back button or if he/she has just entered the page anew. A javascript checks the value to see if the 2 are different and if so should then refresh the page. Can anyone give me a hand on this one? Thanks in advice.
Rob
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50674

When you do a "view source" the browser will show what what it received from the server and will not reflect any chages to the DOM field values made dynamically on the client side.
Upon the resubmit, the server is resubmitting the page as it knows it on the server, again not reflecting any changes you made to the field values.
In order to maintain such state across the requests, you'll need the help of an active server component, such as JSP, to use the submitted fields values as the initial values of the field the second time around.
hth,
bear


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2559

Or you can consider using cookies is they suit your requirement -
http://www.geocities.com/technofundo/tech/js/jscookies.html
HTH,
- Manish
 
 
subject: Preserving State
 
Threads others viewed
Value from select element is null in request
People clicking Submit twice confuses database
URGENT!!!!
How to add error message before sendRedirect
validation problem
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture