This code will do something after submitting form1
1 2 3 4 5 6 7 |
<script> $("form1").submit(function(){ alert("Submitted"); }); </script> |
This code will STOP/PREVENT a form Submitting
1 2 3 4 5 6 7 8 9 10 |
<script> $(document).ready(function(){ $("form").submit(function(event){ event.preventDefault(); alert("Submit prevented"); }); }); </script> |
This code will stop the enter key being used to submit a form.
1 2 3 4 5 6 7 8 9 10 |
$(document).ready(function() { $(window).keydown(function(event){ if(event.keyCode == 13) { event.preventDefault(); return false; } }); }); |
Submit with a normal button, NOT a submit button
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> <script> $(document).ready(function(){ $("#submit4").click(function() { $("form").submit(); }); }); </script> <form action="http//www.google.co.uk" method="post" id="form1"> First name: <input type="text" name="FirstName" value="Mickey"><br> Last name: <input type="text" name="LastName" value="Mouse"><br> <input type="button" value="Submit" id="submit4"> </form> |