Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Saving information on the screen during a page reload

Posted on 2004-09-23
10
Medium Priority
?
275 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
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!

 

Author Comment

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

Accepted Solution

by:
thecode101 earned 600 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

886 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