The Bobster
The Bobster

Reputation: 573

jQuery serializeArray using $(this)

I'm using jQuery's serializeArray to serialize form data, in two different ways.

The "Save All Rooms" button serializes all the form data (this is working fine), and the "Check Availability" button serializes data only from the specific form the button is click for (this isn't working).

Can anyone advise where I'm going wrong? Any help much appreciated!

JSFiddle: https://jsfiddle.net/kuohhm2q/

"Check Availability" function which isn't working:

// Serialize Individual Form Data
el.find(".check_availability" ).click(function() {

   var formData = JSON.stringify( $(this).parent('div :input').serializeArray() ); 
   alert(formData);

});

Upvotes: 1

Views: 85

Answers (1)

Sandeep Nayak
Sandeep Nayak

Reputation: 4757

I changed

 JSON.stringify( $(this).parent('div :input').serializeArray() ); 

to this

JSON.stringify($(this).parent('div').find("input, select").serializeArray() );

Here is the updated fiddle

Upvotes: 1

Related Questions