2

I have a webpage with three buttons, two of the buttons action the form submitting data to the server, it then sends back the appropriate page. The third button is meant to just open a new webpage in a new tab, the current page does not need to be reloaded so this button is just a button element with some onclick() code, its is not part of an input element

The trouble is that when I click on the third button it actions the form action the form even though its not an input type, why does it do this ?

<main> <form action="/license.process" name="process" id="process" method="post"> <label> Please enter your license information as provided in your license email </label> <table> <tr> <td><label title="Email">Email</label></td><td><input type="text" name="licenseEmail" value="[email protected]" class="licenseinputfield"></td> </tr> <tr> <td> <label title="License Key 1"> License Key 1 </label> </td> <td> <input type="text" name="licenseKey1" value="50302c02147f23ed809a8f2579338121a2b1594f967bb18" class="licenseinputfield"> </td> </tr> <tr> <td> <label title="License Key 2"> License Key 2 </label> </td> <td> <input type="text" name="licenseKey2" value="0ff02146cd1777d7e0890e659b10218761869212d7b0d60" class="licenseinputfield"> </td> </tr> </table> <input type="submit" name="cancel" value="Cancel"> <input type="submit" name="save" value="Save"> <button onclick="window.open(&#x27;http://www.jthink.net/songkong/buy.jsp&#x27;,&#x27;_blank&#x27;);"> Get License </button> </form> </main> 

I can make it work properly by moving this third button outside of the form. But then I get formatting problem because button is shown on next line, regardless I want to understand why having the butto within the form triggers the form.

2 Answers 2

3

The default type of a <button> is submit.

If you want it to be type=button then you have to say so explicitly.

Sign up to request clarification or add additional context in comments.

1 Comment

Except on IE7 because Microsoft ;D
1

You need to add the type="button" attribute to prevent the form from being submitted.

I'm not entirely sure why but came across this last week.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.