Use jQuery to ignore form submit when clicking an input

javascript, jquery

Solution

Try this:

$('input.searchplease').click(function (e) {
   $(this).attr('disabled', 'disabled');

   alert('Yep');
   //Do Ajax

   e.preventDefault();
});

Problem

I have a form with a submit input and I need that when the button gets clicked, my script do some Ajax actions. Also I need to disable that button during the Ajax request. So I need a jQuery command to avoid real form submit when input is clicked. I tried to use this: ``` $('input.searchplease').click(function () { $(this).attr('disabled', 'disabled'); alert('Yep'); //Do Ajax }); ``` This didn't worked. I mean, the alert shown correctly but form is submitted. So what is your suggestion?

Original source