history.back()

marco.manni

Utente Attivo
10 Set 2003
49
1
0
Salve a tutti!
Se con JavaScript scrivo history.back() e il back punta ad una pagina con un form, non è possibile dopo aver effettuato il back scrivere dentro una casella di input del form?
Mi spiego meglio: in un form, per errore l'utente sbaglia la digitazione ed effettua il Submit. Dopo aver visualizzato una pagina con il mess di errore, il tasto "indietro" dovrebbe ripresentarmi la pagina col form con una modifica in una casella di testo del form (es. l'utente in quella casella aveva scritto "ciao", io dopo il mess e il tasto "indietro" voglio che mi si ripresenti il form con la casella in cui aveva scritto "ciao" vuota).

E' possibile o kiedo troppo?!
 

Guido Piazza

Utente Attivo
28 Ott 2003
36
0
0
Questo codice l'ho "prelevato" da una faq di jsdir.com ... Penso possa esserti d'aiuto


<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.1">
//--Standard type-class for cookie--
//--inizio--
function Cookie(document, name, hours, path, domain, secure)
{
this.$document = document;
this.$name = name;
if (hours)
this.$expiration = new Date((new Date()).getTime() + hours*3600000);
else
this.$expiration = null;
if (path) this.$path = path; else this.$path = null;
if (domain) this.$domain = domain; else this.$domain = null;
if (secure) this.$secure = true; else this.$secure = false;
}

function Cstore()
{
var cc = "";
for (var prop in this)
{
if ((prop.charAt(0) == '$') || ((typeof this[prop]) == 'function'))
continue;
if (cc != "")
cc += '&';
cc += prop + ':' + escape(this[prop]);
}
var biscotto = this.$name + '=' + cc;
if (this.$expiration)
biscotto += '; expires=' + this.$expiration.toGMTString();
if (this.$path) biscotto += '; path=' + this.$path;
if (this.$domain) biscotto += '; domain=' + this.$domain;
if (this.$secure) biscotto += '; secure';
this.$document.cookie = biscotto;
}

function Cload()
{
var tutti = this.$document.cookie;
if (tutti == "")
return false;
var aa = tutti.indexOf(this.$name + '=');
if (aa == -1)
return false;
aa += this.$name.length + 1;
var zz = tutti.indexOf(';', aa);
if (zz == -1)
zz = tutti.length;
var cc = tutti.substring(aa, zz);
var a = cc.split('&');
for(var i=0; i < a.length; i++)
a = a.split(':');
for (var i = 0; i < a.length; i++)
this[a[0]] = unescape(a[1]);
return true;
}

function Cremove()
{
var biscotto;
biscotto = this.$name + '=';
if (this.$path) biscotto += '; path=' + this.$path;
if (this.$domain) biscotto += '; domain=' + this.$domain;
biscotto += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
this.$document.cookie = biscotto;
}

new Cookie();
Cookie.prototype.store =Cstore;
Cookie.prototype.load = Cload;
Cookie.prototype.remove = Cremove;
//---------------------------------------------
//[email protected]
//--http://www.jsdir.com--------
//--copyright © 2001-------
//------------------------------
nm=new Array()
var visita = new Cookie(document, "contavisita", 2400);
function mem()
{
for(kk=0; kk<5; kk++)
nm[kk]=document.form1.elements['T'+[kk]].value
if (!visita.load() || !visita.name || !visita.cogn || !visita.ind || !visita.tel || !visita.mail)
{
visita.name = nm[0]
visita.cogn = nm[1]
visita.ind = nm[2]
visita.tel = nm[3]
visita.mail = nm[4]
}
if (visita.visits == null)
visita.visits = 0;
visita.visits++;
visita.store();
if(visita.visits >=2)
{
newval=new Array(visita.name,visita.cogn,visita.ind,visita.tel,visita.mail)
for (jk=0; jk<5; jk++)
document.form1.elements['T'+[jk]].value=newval[jk]
}
}
</SCRIPT>
</HEAD>
<BODY onLoad="mem()">
<FORM METHOD="POST" NAME="form1">
<INPUT TYPE="text" NAME="T0" SIZE="20" VALUE="" >nome<BR>
<INPUT TYPE="text" NAME="T1" SIZE="20" VALUE="" >cognome<BR>
<INPUT TYPE="text" NAME="T2" SIZE="20" VALUE="" >indirizzo<BR>
<INPUT TYPE="text" NAME="T3" SIZE="20" VALUE="" >telefono<BR>
<INPUT TYPE="text" NAME="T4" SIZE="20" VALUE="" >email<BR>
<INPUT TYPE="submit" VALUE="Invia" NAME="B1" onMouseDown="mem()"> <BR>
<INPUT TYPE="reset" VALUE="Reimposta" NAME="B2">
</FORM>
</BODY>
</HTML>


Bye Bye
 

Discussioni simili