reche
05-30-2003, 12:38 PM
Hi,
I have cgi script that is using some javascript inputs in the form to give a result page. The cgi script processes the input and gets the result without problem. Howeverr, if you want to submit a new request the browser keeps track of the original input, and that mess alll things up unless I refresh/reload the page. Thereby, I wonder if thereis a simple way (javascript) that would set all the original inputs when the form is reached from the result page after pressing the back buttom of the browser.
Cheers
pedro
Tasmanian Devil
05-30-2003, 12:44 PM
do you want it to remember from after the input is in till when ever or what?
reche
05-30-2003, 12:57 PM
I want the web page to forget what it was in the former input, when the page is reached after pressing the back bottom.
cheers
Tasmanian Devil
05-30-2003, 01:00 PM
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
(:)
var expDays = 999999;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) { endstr = document.cookie.length; }
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value) {
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}
// cookieForms saves form content of a page.
// use the following code to call it:
// <body onLoad="cookieForms('open', 'form_1', 'form_2', 'form_n')" onUnLoad="cookieForms('save', 'form_1', 'form_2', 'form_n')">
// It works on text fields and dropdowns in IE 5+
// It only works on text fields in Netscape 4.5
function cookieForms() {
var mode = cookieForms.arguments[0];
for(f=1; f<cookieForms.arguments.length; f++) {
formName = cookieForms.arguments[f];
if(mode == 'open') {
cookieValue = GetCookie('saved_'+formName);
if(cookieValue != null) {
var cookieArray = cookieValue.split('#cf#');
if(cookieArray.length == document[formName].elements.length) {
for(i=0; i<document[formName].elements.length; i++) {
if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }
else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }
else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }
else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }
}
}
}
}
if(mode == 'save') {
cookieValue = '';
for(i=0; i<document[formName].elements.length; i++) {
fieldType = document[formName].elements[i].type;
if(fieldType == 'password') { passValue = ''; }
else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }
else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }
else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }
else { passValue = document[formName].elements[i].value; }
cookieValue = cookieValue + passValue + '#cf#';
}
cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter
SetCookie('saved_'+formName, cookieValue, exp);
}
}
}
// End -->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" background="http://foxvalleynews.com/clouds.jpg" body onload="cookieForms('open', 'login')" onunload="cookieForms('save', 'login')">
<form name=login>
<table width=452 border=0 cellpadding=0 align="left">
<tr>
<td colspan=3 height="99">
<center>
<font size="+2"><b><font size="+5" face="Times New Roman, Times, serif">Please
Login</font><br>
</b></font><br>
<font face="Geneva, Arial, Helvetica, san-serif" size="3">If you are
a new user, just press the login button<br>
otherwise type in your username and then press the login button.</font>
</center>
</td>
</tr>
<br>
<tr>
<td width="75">Username:</td>
<td width="130">
<input type=text name=username value="new user">
</td>
<td width="239"> </td>
</tr>
<tr>
<td align=center width="75"> </td>
<td align=center>
<div align="center">
<input type=button value="Submit!" onClick="Login()" name="button">
</div>
</td>
<td align=center> </td>
</tr>
</table>
</form>
</body>
</html>
Give that a try, if you want the cookie to expire, then just adjust the experation date.
Tasmanian Devil
05-30-2003, 01:01 PM
never mind then, that will remember it sorry