0

I have a simple form that looks like this:

<form action = '../../uploadGI/index.php' method = 'post' target = '_blank'>
... (inputs)
<button class='btn actionbtn closebtn' onClick = 'this.form.submit()' ... >Submit</button>
</form>

The forms sends a number of parameters to a new page where the user can upload a document (or scan it), the parameters are related to the type of doc, the table and table record it refers to in the db.

When I leave target = "_blank" out the form works as intended. But with target _blank the button opens the page ... twice. What is causing this behaviour?

Nicola Ibba
  • 77
  • 1
  • 8
  • the default action for a button input in a form is to submit the form. No need for the onclick handler. – phuzi Dec 16 '20 at 14:37
  • 1
    Does this answer your question? [How to prevent buttons from submitting forms](https://stackoverflow.com/questions/932653/how-to-prevent-buttons-from-submitting-forms) – Peter Wolf Dec 16 '20 at 14:38

1 Answers1

2

The default action for a button input in a form is to submit the form. No need for the onClick attribute/handler. Just remove the onClick

<button class='btn actionbtn closebtn' ... >Submit</button>
phuzi
  • 12,078
  • 3
  • 26
  • 50