I want to serialize my form using SerializeJSON and I have a div which have multiple tab inside and each tab have multiple form. How can i loop inside the div to get the tab and inside each tab I want to get the form so I can serialize it and after that put it inside array according to the desired structure.
<div class="clamp-content"> <div id="tab1"> <form id="materialinfo"> <input name="plateMaterial"> <input name="plateMaxAllowableStressDesignTemperature"> </form> <form id="defectparam"> <input name="Def_L"> <input name="DefL_2"> </form> </div> <div id="tab2"> <form id="materialinfo"> <input name="plateMaterial"> <input name="plateMaxAllowableStressDesignTemperature"> </form> <form id="defectparam"> <input name="Def_L"> <input name="DefL_2"> </form> </div> </div> the desire structure that I want is something like this:
CaseInfo: 0: {{plateMaterial:"plateMaxAllowableStressDesignTemperature"}, {Def_L: "", DefL_2: ""} 1: {{plateMaterial:"plateMaxAllowableStressDesignTemperature"}, {Def_L: "", DefL_2: ""} I have tried something like this:
var designParameter = []; var form = {}; function save() { $('.clamp-content').children().each(function () { $(this).find('form').each(function () { form = $(this).serializeJSON(); console.log(form) }); }); } But when I console log the form, what I got is:
{plateMaterial: "", plateMaxAllowableStressDesignTemperature: "", plateMaxAllowableStressOperatingTemperature: "", plateThickness: "", boltMaterial: "", …} {Def_L: "", DefL_2: "", Def_D: "", DefD_3: "", DefD_2: "", …} {plateMaterial2: "", plateMaxAllowableStressDesignTemperature2: "", plateMaxAllowableStressOperatingTemperature2: "", plateThickness2: "", boltMaterial2: "", …} {Def_L2: "", DefL_22: "", Def_D2: "", DefD_32: "", DefD_22: "", …} Any help would be greatly appreciated. Thank You :)