Torben
Torben

Reputation: 5494

JQuery - on-Function

can this code affect other submit buttons which are not in the with the id="form_data_voting" ? I assume not, right? And the 3rd line does just affect the code of the with the id #form_data_voting as well, right?

jQuery('body').on('submit', '#form_data_voting', function() {

var formContents = jQuery(this).serializeArray();           
var formSource = jQuery(this).find('input[type="submit"]').attr("alt");

I'm facing problems with two plugins in wordpress which are both activated and the submit button of the other plugin does not work correctly...

Thanks!

Upvotes: 0

Views: 40

Answers (3)

devBinnooh
devBinnooh

Reputation: 611

Yes, this applies only on the id=#form_data_voting. (including the third line)

In the mean time, this is not complete code, the { has to be closed.

if it was like this

jQuery('body').on('submit', '#form_data_voting', function() {

  var formContents = jQuery(this).serializeArray();           
  var formSource = jQuery(this).find('input[type="submit"]').attr("alt");
}

Then this should work as expected. and yes to your questions.

Upvotes: 0

soyuka
soyuka

Reputation: 9105

You could force the submit, but it's kinda strange.

$('.your-other-submit').on('click', function(e) {
    e.preventDefault();
    $('#form_data_voting').submit();
});

It will run your previous code.

You might even get some more external forms within the submit :

var otherFormContents = jQuery('#yourOtherForm').serializeArray();  

I agree with @Archer btw.

Upvotes: 0

Reinstate Monica Cellio
Reinstate Monica Cellio

Reputation: 26143

It's actually an event handler for the form being submitted, as opposed to the button being clicked, so it will handle programmatic submits as well as people pressing enter on inputs that trigger submit.

And yes, the third line of code will only find the submit element(s) within the form specified.

Upvotes: 1

Related Questions