jQuery document on submit -


i using jquery post forms through ajax this:

$(document).on("submit",this.id, function (e) {     // stuff  }) 

this way takes id of form , uses id handle necessary things data different forms on different pages.

this works prefect 1 form on page. when have multiple forms (with unique id's) fails, not respond/trigger anymore.

i know can enter id of form myself , use multiple $(document).on... in jquery approach using now.

is there way solve this?

you don't need pass or use id, have scope problem.

use such code instead more flexible:

$(document).on("submit", "form", function (e) {     var oform = $(this);     var formid = oform.attr("id");     var firstvalue = oform.find("input").first().val();     alert("form '" + formid + " being submitted, value of first input is: " + firstvalue);     // stuff      return false; }) 

using $(this) reference form being submitted, inside event handler. can use wish, instead of finding form scratch.

live test case.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -