submit multiple forms with same name with one click Jquery

前端 未结 1 1142
星月不相逢
星月不相逢 2021-01-28 09:48

I have forms in loop that are created dynamically , and I need to submit all of them with one click, i am following the code below. Can you please suggest me how can I do this

1条回答
  •  隐瞒了意图╮
    2021-01-28 10:47

    You can iterate through all the forms with the given name and submit one by one

    $(document).ready(function () {
        $("#submitButton").click(function () {
            var $form1 = $("#form1");
            $.post($form1.attr("action"), $form1.serialize(), function () {
                alert('Form 1 submitted');
            });
    
            $('form[name="formsub"]').each(function () {
                var $form = $(this);
                $.post($form.attr("action"), $form.serialize(), function () {
                    alert('Form 2 submitted');
                });
            })
        });
    });
    

    0 讨论(0)
提交回复
热议问题