Jquery submit vs javascript submit

I am trying to trigger a form check when a regular button is clicked. This is similar to working with jQuery, but not with simple javascript. Can someone explain this difference between jquery.submit () and javascript.submit () methods? Or what am I doing wrong?

<html> <head> <title>Form Submit</title> <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> function validateForm(form) { if (form.username.value=='') { alert('Username missing'); return false; } return true; } </script> </head> <body> <form action="index.php" name="loginform" method="post" onsubmit="return validateForm(this);"> <input name="username" placeholder="username" required="required" type="text" /> <input name="send1" type="button" value="Login1" onclick="$(document.forms.loginform).submit();" /> <input name="send2" type="button" value="Login2" onclick="document.forms.loginform.submit();" /> <input name="send3" type="submit" value="Login3" /> <a href="" onclick="event.preventDefault(); $(document.forms.loginform).submit();"> Login4 </a> <a href="" onclick="event.preventDefault(); document.forms.loginform.submit();"> Login5 </a> </form> </body> </html> 

onsubmit results

+6
source share
1 answer

The DOM submit() method does not start sending events. jQuery does.

+14
source

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


All Articles