jQuery form submit event not working

jquery form submit not working
jquery submit form ajax
jquery submit form on button click
jquery prevent form submit
jquery get form data after submit
call javascript function on submit button
form on submit
javascript form action submit

I don't know what is wrong with that, because I was following at every step the tutorial from jquery.com regarding the form submit event.

My javascript:

[Ofc. latest jQuery library is included].

<script type="text/javascript">
$("form#addFav").submit(function(event) { event.preventDefault(); alert("hello"); });
</script>

Have also tried with the $(document).ready() event:

$(document).ready(function(){
$("form#addFav").submit(function(event) { event.preventDefault(); alert("hello"); });
});

Here is my HTML form code:

<form action="" id="addFav">
     <input type="text" name="name" class="thin-d"/>
     <input type="submit" value="Send"/>
</form>

So , regarding the above javascript code, it is supposed to work (I mean it should prevent default action [submitting form] and send the alert then), but it all doesn't work - have tried with thousands of combinations, but I fail'd. So I'm waiting for your solutions, guys. I'd appreciate every one.


You probably have some syntax error or somthing like that somewhere else, because what you have just works.

Are you sure there aren't any JS errors?

P.S. I would alwyas go for the latter code to ensure that the elements are in the DOM before trying to attach events.

Form Submit jQuery does not work, As mentioned, you need to submit the form using a simpler event than the jQuery one. BUT you also need to cancel the clicks on the links. I'm using jQuery to submit my form variables, and im trying to prevent the form from submitting via the usual ways (click submit button or press enter on one of the fields) i have this: $('#form').submit(function(){ event.preventDefault(); }); but it doesn't seem to work my form is still submitting, going to the process.php page..


For anyone else who has the same problem, and still struggling to solve this issue, try to see if you have illegally reused the id, and try changing the form id to something unique.

I had accidentally given the id to two different DOM elements and the event was being bound to the first element with the respective id and my form was the second one so it was never captured. This had me pulling my hairs for quiet a long.

.submit(), Description: Bind an event handler to the "submit" JavaScript event, or trigger that However, scripts that rely on event delegation with the submit event will work Forms and their child elements should not use input names or ids that conflict  As mentioned, you need to submit the form using a simpler event than the jQuery one BUT you also need to cancel the clicks on the links Why, by the way, do you have two buttons? Since you use jQuery to submit the form, you will never know which of the two buttons were clicked unless you set a hidden field on click.


I just recently ran into the same issue. Jquery on submit would not work on the form, however just changing it to click event worked fine. Still at a loss why .on(submit) or .submit() events will not recognize the form.

$("form#addFav").click(function (event) {
    event.preventDefault(); alert("hello");
    $(this).submit();
});

Form Submit event not firing when click on text of , When you click on the text of the submit button the form submit event does not fire but if you press anywhere else on the button it works fine. The form.submit points at the element named submit as opposed to the function which submits the form. comment:15 follow-up: 16 Changed 8 years ago by kobyssh Still occurs on Chrome (18.0.1025.162 m)


this question is old but.. you might have had another submit events firing before yours fired. If these other events contained "return false;" statement then the event execution got interrupted and your code never fired. To put your code BEFORE these events you might use ONSUBMIT form attribute where you can put code that will fire before or at the same time as other events.

Jquery .submit event not capturing - JavaScript, I'm trying to do a form validationhowever, i can't get the submit event to work. So I tried to alert a message when the form submits. But the form submits without  Well, the submit method will not work if jQuery can't get the form element, and jQuery doesn't give any error about that. If your script is placed in the head of the document, make sure the code runs after DOM is ready. So, $(document).ready(function () { // your code here // }); will solve the problem.


HTMLFormElement: submit event, Note that the submit event fires on the <form> element itself, and not on any <​button> or <input type="submit"> inside it. However, the SubmitEvent which is sent to indicate the form's submit action Working Draft, No change. jQuery form validate not working. not the actual form submit. (i.e. it does the validation checking whenever the form submit event is triggered by anything).


Forms: event and method submit, Click <input type="submit"> . Both actions show alert and the form is not sent anywhere due to return false :. In addition, the default submit action on the form will be fired, so the form will be submitted. The JavaScript submit event does not bubble in Internet Explorer. However, scripts that rely on event delegation with the submit event will work consistently across browsers as of jQuery 1.4, which has normalized the event's behavior.


jQuery submit() Method, This event can only be used on <form> elements. The submit() method triggers the submit event, or attaches a function to run when a submit event occurs. Syntax. The submit event occurs when a form is submitted. This event can only be used on <form> elements. The submit () method triggers the submit event, or attaches a function to run when a submit event occurs. How to prevent the form being submitted using the event.preventDefault () method.