Skip to content Skip to sidebar Skip to footer

Form Submit - Preventing Page Reload Jquery

I'm building a contact form and i want to submit the data through ajax and display the result back via the same. But whenever user clicks on submit button, the page seems to be sub

Solution 1:

What you actually want is to capture the submit(), and preventDefault() on that.

$('#contactform').submit(function(e){
    e.preventDefault();
});

Solution 2:

jQuery needs a # to identify id and . for class.

If you do not want to submit the form use this:

$("#contactform").on('submit', function(e){

    alert("not submited");
    returnfalse;

    });

Solution 3:

There's a couple things you can take a look at. First, change from type="submit" to type="button". That gives you all the same functionality without the submit. Second, if you're trying to get this to work in IE, it's not working because IE doesn't have the preventDefault method on the event object. You can just set the returnValue to false.

$("#contactform").submit( function(e){
   e.stopPropagation();
   if(e.preventDefault){
      e.preventDefault();
   }else{
      e.returnValue = false;
   }
});

Solution 4:

Sergio is right.

Also, the click listenter will never work on the input either, the right selector is

$('input[name="contact_submit"]')

Post a Comment for "Form Submit - Preventing Page Reload Jquery"