0

I have a simple HTML form:

  <form action="https://[URL goes here]" method="POST">
    <input type="radio" name="args" value="on">Value 1.
    <br>
    <input type="radio" name="args" value="off">Value 2.
    <br>
    <input type="submit" value="Submit!">
  </form>

The problem I'm having is that the URL is returning some status information and the page reloads with that status information. I'd like the page that the form is on to simply reload and ignore any response from the server.

I've tried to replace the

    <input type="submit" value="Submit!">

with

    <input type="submit" onclick="return false" value="Submit!">

but that does not work. I need to pass the "args" value with the form, but I don't care what the server returns. How do I do this?

Alligator
  • 691
  • 3
  • 11
  • 21
  • What does the form submit to? Do you expect the form to retain the previously-entered values, or should it be a blank form? – Tieson T. Sep 13 '15 at 00:16

3 Answers3

2

You could possibly use iframe:

<form action="https://www.google.com/search" target="ignore" onsubmit="this.reset();">
  Search for: <input type="text" name="q" value="Forms"/>
  <input type="submit"/>
</form>
<iframe name="ignore" src="about:blank" style="display:none;"></iframe>
  • This isn't working. The action and arguments are not submitted to the remote server in my code when I set the target as the iframe. UPDATE - it is working. I removed the 'src="about:blank"' language from the iframe, and it works! Thanks. – Alligator Sep 13 '15 at 18:14
1

This question provides some easy suggestions for how to do this.

Submit form without page reloading

In summary:

  • use ajax (requires JavaScript)
  • use an iframe (no JavaScript!)

Just for completeness I'll add that if you have control over the server, you could:

  • return HTTP status 204 No content (still no JavaScript!)

which means: success, but nothing to do. So the browser stays put.

(there's also 205 Reset Content which should reset the form, but I'm not sure how well that's handled by browsers)

More information here: https://benramsey.com/blog/2008/05/http-status-204-no-content-and-205-reset-content/

Community
  • 1
  • 1
Kai Carver
  • 2,240
  • 29
  • 23
0

You could Submit the Form with Ajax. And call

location.reload();

To reload you page.

MadClown
  • 124
  • 7