sehummel
sehummel

Reputation: 5568

Submit button and jQuery

I was told by someone on this site that it was best not to write inline function calls in your HTML when doing jQuery. It sounds like a good plan.

So using jQuery, how do I call a function upon a button submission?

Upvotes: 2

Views: 153

Answers (4)

parent5446
parent5446

Reputation: 898

Others already answered on how to do a form submission, but if you mean you just want to click the button then you would want to use

$('input[name=myButton]').click()

jQuery docs on click();

Upvotes: 0

Brook
Brook

Reputation: 6009

Based on your question, there are 2 different events you might want to use.

If you want to capture the button click, then you want the "click" event of the button

If you want the form submit, then you want "submit" event of the form.

Upvotes: 3

karim79
karim79

Reputation: 342635

You mean form submission. And you can do it by binding an onsubmit event handler to your form:

$("#myForm").submit(function() {
    // do something
});

Upvotes: 3

jyoseph
jyoseph

Reputation: 5455

$('form[name=myForm]').submit(function(){

// function here

});

jQuery docs on submit();

Upvotes: 2

Related Questions