Onsubmit form opposite onclick submit button

UPDATE From @BrendanEich

@mplungjan onclick submit just drops out of this button; the onsubmit form is clearly better.


What would be the reason to use the submit button onclick button to determine if the form should be submitted?

I sure that

  • perform something before sending and cancel sending in case of error, the onsubmit-event form is the obvious place to post it.
  • If you use the submit buttons onclick and then decide to use type = "image", the event handler will fail in many browsers
  • if you change the sending to a button, you will also have to add submit to the onclick event handler.

I am looking for strong reasons to prefer using the onclick submit button on the onsubmit form.

UPDATE: Please, not that I am personally knowledgeable about the many problems associated with submitting and validating the form.
For example, if the javascript view does not initiate onsubmit http://jsfiddle.net/mplungjan/3A4Ha/

<form onsubmit="alert('onSubmit called')"> <input type="text" value="This will submit on enter but in IE the onclick is not triggered" style="width:100%"/><br/> <input type="submit" onclick="alert('Clicked')" /> </form><br /> <a href="#" onclick="alert('Submitting by script'); return false">Submit by script will not trigger onsubmit</a> 

In addition, IE will not launch onclick if you press enter on the form in my fiddle


History:

Came into discussion here

html button is not available without shutdown

I strongly dislike the fact that I used the submit button for NOTHING because of the many 1 years that it doesn’t work on a number of browsers, mostly an older version of IE. I have listed some of the obvious reasons, but I am sure that they will not convince a seasoned user.

Can the SO community help me nail this to the wall as if they nailed w3schools? Also feel free to comment on how I can formulate this question in an acceptable way.


1: since NS2.x and IE3.02

+11
source share
1 answer

The onsubmit form is a more correct approach for the simple reason that the form can also be submitted using the <ENTER> key, rather than just clicking the submit button.

+12
source

Source: https://habr.com/ru/post/894031/


All Articles