input in a text box still appear after page refresh for IE but notFF, Chrome, Opera

A

albert kao

I want to keep the value of the user input (e.g. text box value)
displayed after page refresh by a javascript.
The following test web page is used.
The alerts appear before and after the page refresh as expected on all
browsers (FF, Chrome, Opera & IE).
The input value in a text box still appear after page refresh for IE
but not FF, Chrome, Opera.
Please help to make it work for FF, Chrome, Opera.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" media="all" href="css/
style.css" />
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>Cookie</title>
</head>

<body>
<div>
<br>
Rows Per Page
<input type="text" name="rowsPerPage" id="rowsPerPage" />
<input type="submit" value="savevalue" onClick="savevalue()">
</div>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/Cookie.js"></script>
<script type="text/javascript">
Cookie.init({name: 'mydata'});

function savevalue() {
var rowsPerPageElem =
document.getElementById("rowsPerPage");
alert('rowsPerPageElem.value ' + rowsPerPageElem.value);
Cookie.setData('rowsPerPage', rowsPerPageElem.value);

window.location.reload(true);
var rowsPerPage = Cookie.getData('rowsPerPage');

alert(' rowsPerPage ' + rowsPerPage);

var rowsPerPageElem =
document.getElementById("rowsPerPage");
rowsPerPageElem.value = rowsPerPage;
}
</script>
</body>
</html>
 
T

Thomas Allen

            window.location.reload(true);

The field value will persist if you do not pass true to reload call.
Also, you probably want the savevalue function to return false so that
the form is not actually submitted.

Thomas
 
T

Thomas 'PointedEars' Lahn

Thomas said:
The field value will persist if you do not pass true to reload call.

Not guaranteed.
Also, you probably want the savevalue function to return false so that
the form is not actually submitted.

That would be the case if the return value of savevalue() would be returned
to an `onsubmit' handler of a form, but there is none here which is the
problem.


PointedEars
 
T

Thomas 'PointedEars' Lahn

albert said:
I want to keep the value of the user input (e.g. text box value)
displayed after page refresh by a javascript.
The following test web page is used.
The alerts appear before and after the page refresh as expected on all
browsers (FF, Chrome, Opera & IE).
The input value in a text box still appear after page refresh for IE
but not FF, Chrome, Opera.
Please help to make it work for FF, Chrome, Opera.

0. RTFM, STFW, RTFFAQ: <http://jibbering.com/faq/#posting> pp.
1. Make it Valid HTML: <http://validator.w3.org/>
2. Lose Prototype.js and probably Cookie.js, too.
3. Use the `onload' attribute of the `body' element to fill the controls
with the cookie data.
4. Add a server-side fallback.


PointedEars
 
J

JR

I want to keep the value of the user input (e.g. text box value)
displayed after page refresh by a javascript.
The following test web page is used.
The alerts appear before and after the page refresh as expected on all
browsers (FF, Chrome, Opera & IE).
The input value in a text box still appear after page refresh for IE
but not FF, Chrome, Opera.
Please help to make it work for FF, Chrome, Opera.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
   <head>
      <link rel="stylesheet" type="text/css" media="all" href="css/
style.css" />
      <meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
      <title>Cookie</title>
   </head>

   <body>
      <div>
         <br>
         Rows Per Page
         <input type="text" name="rowsPerPage" id="rowsPerPage" />
         <input type="submit" value="savevalue" onClick="savevalue()">
      </div>
      <script type="text/javascript" src="js/prototype.js"></script>
      <script type="text/javascript" src="js/Cookie.js"></script>
      <script type="text/javascript">
         Cookie.init({name: 'mydata'});

         function savevalue() {
            var rowsPerPageElem =
document.getElementById("rowsPerPage");
            alert('rowsPerPageElem.value ' + rowsPerPageElem.value);
            Cookie.setData('rowsPerPage', rowsPerPageElem.value);

            window.location.reload(true);
            var rowsPerPage = Cookie.getData('rowsPerPage');

            alert(' rowsPerPage ' + rowsPerPage);

            var rowsPerPageElem =
document.getElementById("rowsPerPage");
            rowsPerPageElem.value = rowsPerPage;
         }
      </script>
   </body>
</html>

Use the IE's 'autocomplete' attribute, e.g.

<input autocomplete="off" ...>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top