1

I have two tabs, both contains forms Now I have one common submit button for which my onclick event is here -

var data = $('#fm').serializeArray();
            data.push({name: 'id', value: row.id});
            $.post('save_detail.php',
                data,
                function(data2){
                    $.messager.alert('Info', data2, 'info',function(){
                        $('#dlg').dialog('close');
                    });
                }
            );

Now what i want to do is have a seperate form in two tabs and then send both their data together. I already tried -

var data2 = $('#fm2').serializeArray();
            data.push(data2);

But failed. So how can i do it, can anyone help?

Harshit Laddha
  • 2,044
  • 8
  • 34
  • 64
  • Check here : http://stackoverflow.com/questions/7843355/submit-two-forms-with-one-button – shivshankar Mar 28 '14 at 12:37
  • No but that is plain submitting. I can't make two submit calls as shown in that question document.forms["form1"].submit(); document.forms["form2"].submit(); my server side script depends on data both from the fm and fm2 – Harshit Laddha Mar 28 '14 at 12:41
  • 1
    ohh...ok. Then in that case in the same code block you can post data to two files as you posted in your first code block. – shivshankar Mar 28 '14 at 12:47
  • Yes, we could have done that. But my server side script requires all variables at once so if i make the post two times then the data would be seperate. Also i found the solution by debugging sorry for inconvenience. data2 is an array i had to iterate over it and then push the array items individually in data like - var data2 = $('#fm2').serializeArray(); for(var i=0;i – Harshit Laddha Mar 28 '14 at 12:51

1 Answers1

0

the serialize option creates an array of name and value pairs so that's why if i push the result of one serialize to another it wont work as it will push an array not a key value pair so the possible solution i found was

var data2 = $('#fm2').serializeArray();
            for(var i=0;i<data2.length;i++)
                data.push({name:data2[i]['name'],value:data2[i]['value']})
            console.log(data);  
Harshit Laddha
  • 2,044
  • 8
  • 34
  • 64