Solved

Saving information on the screen during a page reload

Posted on 2004-09-23
10
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 58
PHP radio buttons with email not sending 24 114
ColdFusion Rereplace 3 97
Problem to copy file 14 91
When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

751 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