Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 2 [or more] forms that I wanna to submit them with one button.
first form have been post to class1 and form2 posted to class2; like below:

HTML
                            <form id="form1" action="class1/add" method="post" >
                                <fieldset>
                                    <legend>test</legend>
                                      <label>name*<small></small></label><input autocomplete="off" type="text" name="name" required="required" />
                                    
                                </fieldset>
                            </form>
                            



                            <form id="form2" action="class2/add" method="post" >
                                <fieldset>
                                    <legend>job</legend>
                                      <label>job *<small></small></label><input autocomplete="off" type="text" name="job" required="required" />
    
                                </fieldset>
                            </form>
                            
                                  
<button class="button button-gray" onclick="submitform()"><span class="accept"></span>ثبت</button>


and then submitted forms with this script.

JavaScript
submitform = function(){
    //alert("saa");
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}



but I just receive second form.
Can anybody help me?
Posted
Comments
Samer Aburabie 29-Oct-14 3:36am    
This is not possible with html, you only post one form at a time, now what you need to think about is another alternative solution to the problem you are trying to solve here, e.g why not to mix all and prefix the fields with a certain class1, class2, classn prefix.
Karim Pazoki 29-Oct-14 3:57am    
tnx a lot Samer. but I don't wanna to mix them; I wanna submit two form on two class.

1 solution

<script>
    submitform = function(){
        document.getElementById("form1").submit();
        
        setTimeOut(function() {
            document.getElementById("form2").submit();
        }, 5000);
    }
</script>


Karim, I am not sure, whether we can do so or not, as while submitting the first form, it is just redirecting to another URL (class1/add), and where, it is not finding the DOM where form2 present (if we are trying the above code).

So, best if we can use AJAX for submitting the form, and then submit the 2nd form, once we will get success on the first form submit.
 
Share this answer
 
Comments
Karim Pazoki 29-Oct-14 6:28am    
tnx a lot @Prava

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900