I have code like this
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <script type="text/javascript"> $(function(){ $("#main_form").submit(function(){ alert("submitting"); }); $("#main_form").on("submit", function(){ alert("ON submitting"); }); $("#lnk").click(function(){ </script> <h4><?php echo time(); ?></h4> <form id="main_form" action=""> <input type="text" value="x"/> <input type="submit" value="submit-btn"/> </form> <a id="lnk" href="#">test submit js</a>
When I click the "Send" button, I get 2 warnings, so the onsubmit events are fired, but when I click the #lnk link, which should be sent using simple js, for example
document.getElementById("main_form").submit();
I get only a view of the form, but no warnings. But when I uncomment sending via jquery
$("#main_form").submit();
warnings are returned again. Can someone explain to me why this is?
PS I have legacy code that submits the form in plain js, and I would prefer not to change it, so I decided to just bind the onsubmit events and perform some checks in the user-defined function, but I had the problem described above
source share