Prevent Default on Form Submit jQuery
What's wrong with this?
HTML:
<form action="http://localhost:8888/bevbros/index.php/test" method="post" accept-charset="utf-8" id="cpa-form" class="forms">
<input type="text" name="zip" value="Zip code" id="Zip" class="required valid">
<input type="submit" name="Next" value="Submit" class="forms" id="1">
</form>
jQuery:
$("#cpa-form").submit(function(e){
e.preventDefault();
});
Solution 1:
Try this:
$("#cpa-form").submit(function(e){
return false;
});
Solution 2:
Use the new "on" event syntax.
$(document).ready(function() {
$('form').on('submit', function(e){
// validation code here
if(!valid) {
e.preventDefault();
}
});
});
Cite: https://api.jquery.com/on/