Why & lt; input type = & ldquo; button & rdquo; & gt; submit a form?

advertisements
<form name="callEventForm" method="post" action="/PDC/callevent.do">

     ...

     <input type="button" value="Save" name="addCallEvent" id="addCallEvent" onclick="alert('You clicked me!')"/>

     ...

 </form>

When clicking this "Save" button, the form is submitted instead of displaying the alert. I was lead to believe that type="button" would cause the form to not submit on click.


Change:

onclick="alert('You clicked me!')"

To:

onclick="alert('You clicked me!');return false;"