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>