Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery get form values, multiple forms

Tags:

jquery

forms

I have multiple forms on the page and i need to get the values of the form that is submitted, but without specifying the form.

$(document).ready( function (){
 $('form').submit( function(){
       return submitForm()
 });

});

and in the .js file submitForm() should identify the id of the form that is submitted. How can be that done?

I get the values of the form[0], not the one that is clicked

like image 326
Dr Casper Black Avatar asked Nov 28 '25 19:11

Dr Casper Black


1 Answers

Not sure what submitForm() does, but I assume you're somehow using this in it.

If so, try:

 $('form').submit( function(){
       return submitForm.call( this );
 });

Doing it this way should send the context of the form that was clicked to the submitForm() call.

So in submitForm() you can refer to the correct form using this, or in a jQuery object using $(this).


EDIT:

Here's an example of what I mean: http://jsfiddle.net/pXwTE/

like image 156
user113716 Avatar answered Nov 30 '25 12:11

user113716



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!