Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery submit function not working properly

Tags:

jquery

submit

I have some questions with jQuery submit function.

here is work environment

jQuery: 1.7.2, chrome (18.0.1025.168 m).

There are 2 problems.

1st:

my codes like this

html

<form id="test" action="..." method="post">
     <input type="text" />
     <input type="submit">
</form>

jQuery

$('#test').submit(function(){
      return false;
})

the problem is it works fine in firefox and opera but chrome.

2st:

html: as above.

jQuery:

$('#test').submit(function(){
      if(...)
         alert(something..);
      return false;
})

it dosen't work in firefox,opera and chrome. it always trigger form.submit why.

I am very confused it. who can figure it out thanks!

like image 974
jame Avatar asked Aug 31 '26 21:08

jame


2 Answers

Don't use return false;. Try this instead:

$('#test').submit(function(event){
      event.preventDefault();
});
like image 94
moribvndvs Avatar answered Sep 02 '26 11:09

moribvndvs


Replace:

$('#test').submit(function(){
      return false;
});

with:

$('form#test').submit(function(event){    
      event.preventDefault();
});
like image 29
iambriansreed Avatar answered Sep 02 '26 10:09

iambriansreed



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!