Solved

Saving information on the screen during a page reload

Posted on 2004-09-23
10
189 Views
Last Modified: 2010-04-06
Hi Experts,

This problem is hard to explain, but here goes:

I have a few textboxes on my page that a user can enter data in.  There is also other content on the page.  This other content can be changed by clicking links/submitting forms, causing the page to reload with different content.  When this happens, the textboxes and the user's content should not change.

Since there are various ways of reloading the page, is there a generic way to somehow save the text in the textboxes, and then reload this data when the page reloads?

I don't think it's possible to use javascript to move the inputs to whatever form is being submitted because in some cases, a form isn't being submitted.  Instead, a link is being clicked that leads back to the current page, only with a parameter specified in the href.

This is a difficult problem to solve because our application is very large and hasn't taken the problem into account.

Thanks in advance.

Please let me know if I need to clarify/use an example.
0
Comment
Question by:autoknowledge
  • 3
  • 3
  • 2
  • +2
10 Comments
 
LVL 3

Expert Comment

by:thecode101
ID: 12136926
You could do this by adding a onBlur to perform javascript that will store the information in a cookie.

<INPUT TYPE="text" VALUE="" NAME="fieldName" onBlur=addToCookie()>

 <script type="text/javascript" language="JavaScript">

function addToCookie() {
   //Add to cookie code here
}

</script>

Let me know if this will work for you and if you need the javascript code.
0
 

Author Comment

by:autoknowledge
ID: 12137338
thecode101,

Thanks for the recommendation.  I was thinking cookies might be something to look at but I haven't had any experience with using them.  Could you give me a quick example of how I would put the information into the cookie, and then how I would retrieve it?  Also, could you recommend some good online cookie references as well?

Thanks for your response!

-Nathan
0
 
LVL 19

Expert Comment

by:peh803
ID: 12142495
You talk about submitting forms in your question -- what server side language are you using for your pages?

peh803
0
 

Author Comment

by:autoknowledge
ID: 12146216
We're using java for our server side language.
0
 
LVL 3

Accepted Solution

by:
thecode101 earned 200 total points
ID: 12146486
Heres some good javascript cookie sites:
http://members.ozemail.com.au/~dcrombie/javascript/chap14.html
http://www.netspade.com/articles/javascript/cookies.xml
http://www.the-cool-place.co.uk/javascript/cutandpaste/cutandpaste15.html

As soon as I get a chance to write some code, I will do that. If any other java expert has a better way of doing this or wants to finish the code to do this, please feel free.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 13

Expert Comment

by:davidlars99
ID: 12147186
sorry, I don't know Java and I can't help you with server side code, (in your case it's the best solution though...) but I can show you how to pass form values to the next or on the same page. Example uses query string values passed by GET method and captures them on the action page. NOTE, that Internet Explorer allows anly up to 9049 characters in the address bar, other browser a little more...
in order for this to be 100% functional you need a form validation. I didn't include it because It's the simplest thing in Javascript and I hoped you knew it, also easy to understand... :)




<html>
<head>
<script language="JavaScript">

var c=[],temp,i;

function QueryString(str){

    temp=unescape(location.href);
    temp=temp.substring(temp.lastIndexOf('?'), temp.length);
    temp=temp.substring(1,temp.legth);
    temp=temp.split('&');  
    for(i=0;i<temp.length;i++)
           c[i]=temp[i].split('=');
    temp='';
    for(i=0;i<c.length;i++)        
           if(c[i][0]==str)
                return c[i][1]  
}

</script>

</head>
<body>

<form name="f1" action="test.html" method="get">

<input type="text" name="str1" value="">
<br>
<input type="text" name="str2" value="">
<br>
<input type="text" name="str3" value="">
<br>
<br>
<input type="submit" value="Submit">

</form>

<script language="JavaScript">

document.write(QueryString("str1")+"<br>");
document.write(QueryString("str2")+"<br>");
document.write(QueryString("str3")+"<br>");

</script>

</body>
</html>
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 12147225
OR


<form name="f1" action="test.html" method="get">

<script language="JavaScript">

document.write('<input type="text" name="str1" value="'+QueryString("str1")+'"+"<br>">;
document.write('<input type="text" name="str2" value="'+QueryString("str2")+'"+"<br>">;
document.write('<input type="text" name="str3" value="'+QueryString("str3")+'"+"<br>">;

</script>

<input type="submit" value="Submit">

</form>
0
 
LVL 13

Expert Comment

by:davidlars99
ID: 12147249
sorry, little syntax error...


<form name="f1" action="test.html" method="get">

<script language="JavaScript">

document.write('<input type="text" name="str1" value="'+QueryString("str1")+'"><br>');
document.write('<input type="text" name="str2" value="'+QueryString("str2")+'"><br>');
document.write('<input type="text" name="str3" value="'+QueryString("str3")+'"><br>');

</script>

<input type="submit" value="Submit">

</form>
0
 
LVL 3

Expert Comment

by:xakem
ID: 12155411
hello! heh :)
how r u guys?

do you need the data from the form on the server-side any time before last post?

if u do the simplest way is to set form's action attribute to the same page and catch the data from the form by server-side and regenerate the page accordingly setting values of the form controls to the server-side script post/get variables.

if u don't all the data can be stored by JavaScript on the client side without submitting form (it seems like u r trying to control the values entered into the form's controls) just add a function to the onSubmit event handler that will store/control/pass the contents of the controls, if they r ok - submit the form, if not - don't.
0
 

Author Comment

by:autoknowledge
ID: 12163868
Thanks for the responses.

I don't think that adding the variables to the form would be a possibility.  

Here's an example:

In the majority of our pages, we have included a system browser.  This system browser lets the user choose which system they would like to view data for.  The page doesn't change, just the data being displayed on the page.  The systems in this browser are links.  These links point to the current page, but each one contains a different value for a 'system' parameter specified in the link's href.

ie.
<a href="http://www.test.com/app/main?action=browsefiles&system=100">system100</a>
<a href="http://www.test.com/app/main?action=browsefiles&system=200">system200</a>
<a href="http://www.test.com/app/main?action=browsefiles&system=300">system300</a>

Our browser is more complex than this, and is used throughout our application.  However, there isn't a form involved.  To change the system to use a form instead of links would probably be too big of a job.

At the same time, there may be a text box that the user may enter a number in.  If the system is changed, then I don't want this number reset when the page reloads.  Somehow, the data would need to be stored on the user's computer.

Will a cookie be able to handle this?

There are only 2 other solutions that I can think of which I doubt I would be allowed to implement.
One is to create a hidden frame, which I would keep the data stored in as the main page reloads.  After the reload, I would get the data back from the hidden frame.
The second is to actually put the text box in another frame, so that it doesn't reload when the system is changed.

I'm thinking that a cookie would probably be the best bet.  If someone could show me some example code of how this works, it would be a huge help.  

Thanks!
-Nathan
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now