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

Discussion in 'Javascript' started by laryten@yahoo.com, Oct 12, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. Re: How to update the current web page? (delete current web page+ rewrite the page)

    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
    Michael Winter, Oct 12, 2006
    #2
    1. Advertising

  3. Guest

    Michael Winter wrote:
    > 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 <html> and 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, 2006
    #3
  4. Guest

    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, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marcel Kraan (kraan.net)

    mod rewrite

    Marcel Kraan (kraan.net), Aug 3, 2003, in forum: Perl
    Replies:
    1
    Views:
    1,314
    Eric J. Roode
    Aug 3, 2003
  2. Bfons

    rewrite N lines in Perl

    Bfons, Sep 23, 2003, in forum: Perl
    Replies:
    4
    Views:
    2,028
    Bfons
    Sep 24, 2003
  3. Michel

    Rewrite URL with Session possible?

    Michel, Dec 9, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    400
    Michel
    Dec 9, 2003
  4. TruongLapVi

    Rewrite Form action

    TruongLapVi, Feb 20, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    466
    Marshal Antony
    Feb 20, 2004
  5. =?ISO-8859-1?Q?Thomas_Gagn=E9?=
    Replies:
    1
    Views:
    470
    Lee Fesperman
    Nov 21, 2003
Loading...

Share This Page