Reputation: 1843
So this is driving me nuts. This code,
$('#the_form').submit(function(e){
alert("Submit!");
return false;
e.preventDefault();
});
should prevent my HTML form,
<form id="the_form">
<input type="text" name="q" />
<input type="submit" />
</form>
from refreshing the page, but it doesn't. Does anyone have insight on this?
Upvotes: 0
Views: 81
Reputation: 55740
Just remove the return
statement..
Also Make sure your code is encased in DOM ready Handler
$(document).ready( function() {
$('#the_form').submit(function(e){
alert("Submit!");
e.preventDefault();
});
});
Upvotes: 0
Reputation: 318182
$(function() {
$('#the_form').on('submit', function(e){
e.preventDefault();
alert("Submit!");
});
});
Upvotes: 4
Reputation: 1645
Try removing return false
from your code, or putting it after e.preventDefault()
.
Upvotes: 0