当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - JQuery - How do i submit the cloned forms?

问题描述:

how can i submit all the cloned forms at the same time?

I made a script to clone my form, and i want to submit all the cloned forms

How can i do that?

HTML

 <div id='forms'>

<div class='cform'>

<form id='form' method='POST'>

<input style='width: 80px;' class='hihi' type='submit' name='add_jo' value='Submit all' />

<td><input class='txtedit' placeholder='Job name' type='text' name='jo[]' maxlength='130' /></td>

</form>

</div>

</div>

JQuery

 $('.clone').click(function(event){

event.preventDefault();

var tr = $('.cform:first');

var newTr = tr.clone();

newTr.find(":input").val(''); //find all input types (input, textarea), empty it.

newTr.appendTo(tr.parent());

});

网友答案:

Submitting a form is triggering request for new page load, thus you can't submit several forms simultaenously. Try to collect all forms' values in a hidden form to be submitted or use some AJAX to do the job without actually submitting form data.

Alternatively you could clone your form's content to extend the form itself.

<form action="..." method="post">
    <div class="cloneable">
        <input name="data[]" value="" />
    </div>
    <button id="extend">Clone</button>
    <button type="submit" id="submit">Submit</button>
</form>

Your JS might look like this:

 $("#extend").click( function() {
      $(".cloneable")
          .clone()
          .insertBefore( $("#extend") );
 } );
分享给朋友:
您可能感兴趣的文章:
随机阅读: