By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,397 Members | 2,552 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,397 IT Pros & Developers. It's quick & easy.

How to update the current web page? (delete current web page + rewrite the page)

P: n/a
Hi,

Is there a way to update the same web page instead of getting a new
page each time we click the submit button? The simplest thing to do is
to delete the current page (or go back to the previous page) and then
redraw the page. There are a few possible solutions:

1. Use the same URL again. But a new page will still be created.

2. Use the "onsubmit" option:

<form ACTION="testnet.pl" method="post"
ONSUBMIT="javascript:history.go(-1); return false;">
.... <input..>

but the browser goes back to the previous page yet does not
continue to the ACTION part to draw the same page with new data.

3. Leave the page alone and use a customized javascript to update the
input fields of the current page:

<script language="javascript" >
function UPDATE(obj) {
frm1.txt1.value = Date().toLocaleString();
}
....
<form name="frm1">
<input name="foo" ONCLICK="UPDATE(this)" type="button">

4. Someone mentioned that one can post the form to itself. But he/she
did not explained the details.

By using javascript this way, the program still works as usual even if
javascript is turned off. Has anyone done this before?

Oct 12 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
la*****@yahoo.com wrote:
Is there a way to update the same web page instead of getting a new
page each time we click the submit button?
Would you care to clarify what you mean? I presume that you want the
form to remain. Do you want the values to be cleared, too?
The simplest thing to do is to delete the current page (or go back to
the previous page) and then redraw the page.
The simplest thing to do is re-serve the document. You haven't suggested
why that's not possible.

[snip]
<form ACTION="testnet.pl" method="post"
ONSUBMIT="javascript:history.go(-1); return false;">
.... <input..>

but the browser goes back to the previous page yet does not
continue to the ACTION part to draw the same page with new data.
Of course, because you're cancelling the submission.
3. Leave the page alone and use a customized javascript to update the
input fields of the current page:
[snip]

And when scripting is disabled?
4. Someone mentioned that one can post the form to itself. But he/she
did not explained the details.
The same as option 1: submit the form to the same URL, and determine
server-side whether a request is a form submission, or not.

[snip]

Mike
Oct 12 '06 #2

P: n/a
Michael Winter wrote:
la*****@yahoo.com wrote:
Is there a way to update the same web page instead of getting a new
page each time we click the submit button?

Would you care to clarify what you mean? I presume that you want the
form to remain. Do you want the values to be cleared, too?
I have many "Load' submit buttons on the page, one for each file to
be uploaded. So When user clicks one of these 'Load' button, I wish I
can upload the chosen file and refresh the screen with the same
form/page. This way if they upload 10 files and click "Back" button of
the browser, they will go back to the previous page, not the 9 pages
that the browser normally created during the process. (I also have a
"Load All" button to load all files all in once.)
The simplest thing to do is to delete the current page (or go back to
the previous page) and then redraw the page.

The simplest thing to do is re-serve the document. You haven't suggested
why that's not possible.
How to re-serve the document without getting a new page? I thought
the browser always create a new page for the history record that I am
trying to avoid.
[snip]
<form ACTION="testnet.pl" method="post"
ONSUBMIT="javascript:history.go(-1); return false;">
.... <input..>

but the browser goes back to the previous page yet does not
continue to the ACTION part to draw the same page with new data.

Of course, because you're cancelling the submission.
It is merely there to indicate that the browser can only do either
"onclick=history.go(-1)" or "action" in this case. If it executes the
"onclick=history.go(-1)" to go back to the previous page, it is already
on different page/form thus it won't be able to submit anything. This
is why as far as I know no one has used the "history.go(-1)" and submit
(action) as well. The browser just go back to the previous page and
never submit any data to the server so that it can draw a new page.
3. Leave the page alone and use a customized javascript to update the
input fields of the current page:

[snip]

And when scripting is disabled?
Those user who has javascript disabled will see the whole history
stack as usual. Those has javascript enabled will see just one page
that gets updated.
4. Someone mentioned that one can post the form to itself. But he/she
did not explained the details.

The same as option 1: submit the form to the same URL, and determine
server-side whether a request is a form submission, or not.
Whenever I submit a form to the same URL I get a new page unless
there is a way that the server can ask the browser (client) to go to
the previous page first.

I tried to do this by running the javascript:history.go(-1) in the
body. This is the fifth and sixth alternative:

5. Execute javascript when the server sends the form:

<html><body>
<script language="JavaScript">
javascript:history.go(-1); // ask the browser to go back
</script>
</body></html>

<html>body>
<form.... // then draw a new form
<input....>
</body></html>

When I ran it the browser refreshed the screen and went to the
current page again. So it didn't work. I also tried putting the
history.go(-1) inside the second <htmland got same result.

6. Ask the browser to delete the current page first before drawing new
page:

I couldn't find anything on the internet to suggest how to do this.
[snip]

Mike
Oct 12 '06 #3

P: n/a
kas...@yahoo.com wrote:
Michael Winter wrote:
3. Leave the page alone and use a customized javascript to update the
input fields of the current page:
[snip]

And when scripting is disabled?

Those user who has javascript disabled will see the whole history
stack as usual. Those has javascript enabled will see just one page
that gets updated.
Actually you are right, the alternative 3 won't work if the
javascript is disabled.

Oct 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.