user403269
user403269

Reputation: 91

How can I submit two forms on single click?

I have to submit two forms; one is on the page, while the other is coming through combo change event using jquery. I have to get both of these forms values on the same page. Please help me I have already wasted much time.

My code looks like this:

this function which i'm calling on the button click to submit both forms

function forms_submit()
{

document.form1.submit(); 
document.form2.submit();

}

Upvotes: 0

Views: 970

Answers (3)

X10nD
X10nD

Reputation: 22040

If your submit your reason, probably I could submit your 2 forms

-----------edited--------------

var whatever ='<span id='updated_values'><input type=hidden></span>';
use $('#div').append(whatever);

Each time you select a category trigger the whatever to append the an existing form as hidden form type, you need to catch the variables at time of form submission.

Hope this solves your issue.

Upvotes: 0

Cu7l4ss
Cu7l4ss

Reputation: 566

You can use XMLHTTPRequest to send both forms, (but that requires two requests you'd be wasting instead of one) I would recommend joining the forms together.

anyways a codesample,

btnSubmitBoth.onclick = function () {
    var xmlReq,
    data = getFormsData(); // needed to be in format of "something=1&sometinelse=2"
    if (typeof XMLHttpRequest !== 'undefined' && (window.location.protocol !== 'file:' || !window.ActiveXObject)) {
         xmlReq = new XMLHttpRequest();   
     } else {
          try {
                 xmlReq = new ActiveXObject('Msxml2.XMLHTTP.6.0');     
         } catch(e) { }     
         try {
             xmlReq = new ActiveXObject('Msxml2.XMLHTTP.3.0');     
         } catch(e) { }     
         try {
                xmlReq = new ActiveXObject('Msxml2.XMLHTTP');     
        } catch(e) { }   
    }
xmlReq.open("post", url, true);
xmlReq.send(data);
}

Upvotes: 0

Gabriele Petrioli
Gabriele Petrioli

Reputation: 196002

You cannot submit two forms.. since your are in a browser, you can only end to one page.. and it depends on which form you submit.. (unless you go the ajax way)

perhaps you want to merge the forms in a single form in your HTML..

Give some more info/code to get some more specific answers..

Upvotes: 1

Related Questions