How can I refresh a form page after the form submits to _blank?

Hal Carleton picture Hal Carleton · Sep 20, 2013 · Viewed 89.7k times · Source

I have an HTML form which targets _blank. I would like the page that form is on to reload after submitting.

So here's some sample markup:

<form method="POST" action="result.php" target="_blank">
    <label for="name">Name:</label>
    <input type="text" name="name" />

    <label for="email">Email:</label>
    <input type="email" name="email" />

    <input type="submit" value="submit" />
</form>

So when you submit this form it will POST to result.php in a new window or tab. This leaves the form page as is. I want the form page to reload, or at least reset all fields.

I've tried <form onsubmit="location.reload()"... as well as onsubmit="window.location.reload()" but nothing changed.

Any suggestions?

(please no jquery)

Answer

Explosion Pills picture Explosion Pills · Sep 20, 2013

Not sure why window.location.reload() doesn't work. I think it should. However, this does seem to work:

onsubmit="setTimeout(function () { window.location.reload(); }, 10)"