Good day, I just can not win the form ...
The task is, by clicking on the "send" button, check that the form is completed (done), and if the form is filled out correctly - send it ... that it just did not try to invent)

<form id='reg' name='reg'> <input 1....> <input 2....> <input type=submit>// в таком варианте как не извращался форма в любом случае отправляется <input type=button>// в таком варианте как не извращался форма в любом случае НЕ отправляется </form> 

code js reached obsurd

  onclick='this.form.submit();' 

and in a similar spirit found on the Internet

if it's not difficult to write how to send the form from JS or how to cancel sending using JS

  • Can jQuery be used? - pvkovalev
  • <input type = button> Does not trigger a submit event and semantically incorrectly handle this type of button to sign a form. Answer the jQuery question, everything is really simple - likerRr
  • Yes, it is possible, version 1.2 of the checkbox is connected there now) I can connect with the latest version of the incorrectness of this action, is it possible then to cancel submit in the script for the button type <input type = submit>? those. if as a result of the check there was an error in the data) - Vladimir Klykov
  • htmlbook.ru/html/input/required , and for older browsers polyfill. - RubaXa
  • @pvkovalev, I didn’t seem to have such questions) I immediately answered what was possible and what version 1.2 was. Something is already connected there, and it’s clear that if a newer one is needed then this will not be a problem) and thanks for the answer) I will test) - Vladimir Klykov

1 answer 1

If you do not use ajax sending data, the code will be as follows:

 $('#reg').on('submit', function () { var validation = true; if (validation) { // валидация успешна, данные пойдут на сервер return true; } else { // валидация не пройдена, надо вывести ошибки и не отправлять форму return false; } }); 

And do not handle input of type button, since sending can be done by pressing Enter in text input

  • Grateful for the answer) everything happened as it should) - Vladimir Klykov