A
abc
I have a set of web pages each containing a form with GET method. On
submit, I need to parse the form, add element values to the
location.search query, replace the current history location's URL with
the newly constructed one (updated form fields!), and THEN to invoke
the next page. Since each page would run restorePage() function on the
page load, each form would be restored on the browser's back button
request. Here's the brief overview of the logic:
<html>
<head>
<script>
savePage(){
// Parse the form and add parameters to the current location.search
a = location.search.substring(1);
for (i=0; i<form.length; i++){
a += '&' + form.elements.name + '=' + form.elements.value;
}
// Remember form fields' values
location.replace('currentpage.shtml?' + a);
// Pass them to the next page
setTimeout("document.location = 'nextpage.shtml?' + a;", 1000);
return false;
}
restorePage(){
// Parse the query and fill out the form
args = new Array();
pair = new Array();
a = location.search.substring(1);
args = a.split('&');
for (i=0; i<args.length; i++){
pair = args.split('=');
form.elements.value = pair[1];
}
</script>
</head>
<body onLoad="restorePage();">
<form method="get" action="javascipt: savePage();"
onSubmit="checkForm();">
:
:
</form>
</body>
</html>
As could be seen from the code above, I synchronize replace and load
requests, giving the replace request a full second to execute. But -
it doesn't work as expected! It does replace the URL correctly, but it
never loads the next page. On the other hand, if I comment out the
replace request, the next page loads correctly, but I lose the restore
functionality. It appears that these two requests are mutually
exclusive.
I've tested the thing in NS 7.1 on RedHat Linux. Didn't even try it in
IE or FF, assuming it wouldn't work either.
Any suggestion would be greatly appreciated.
submit, I need to parse the form, add element values to the
location.search query, replace the current history location's URL with
the newly constructed one (updated form fields!), and THEN to invoke
the next page. Since each page would run restorePage() function on the
page load, each form would be restored on the browser's back button
request. Here's the brief overview of the logic:
<html>
<head>
<script>
savePage(){
// Parse the form and add parameters to the current location.search
a = location.search.substring(1);
for (i=0; i<form.length; i++){
a += '&' + form.elements.name + '=' + form.elements.value;
}
// Remember form fields' values
location.replace('currentpage.shtml?' + a);
// Pass them to the next page
setTimeout("document.location = 'nextpage.shtml?' + a;", 1000);
return false;
}
restorePage(){
// Parse the query and fill out the form
args = new Array();
pair = new Array();
a = location.search.substring(1);
args = a.split('&');
for (i=0; i<args.length; i++){
pair = args.split('=');
form.elements.value = pair[1];
}
</script>
</head>
<body onLoad="restorePage();">
<form method="get" action="javascipt: savePage();"
onSubmit="checkForm();">
:
:
</form>
</body>
</html>
As could be seen from the code above, I synchronize replace and load
requests, giving the replace request a full second to execute. But -
it doesn't work as expected! It does replace the URL correctly, but it
never loads the next page. On the other hand, if I comment out the
replace request, the next page loads correctly, but I lose the restore
functionality. It appears that these two requests are mutually
exclusive.
I've tested the thing in NS 7.1 on RedHat Linux. Didn't even try it in
IE or FF, assuming it wouldn't work either.
Any suggestion would be greatly appreciated.