Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Submit two forms with one button

    Hope this the right place to post this question.

    I'm trying to Submit two forms with one button and one by one. Submit one by one is working. But can't finger out how to submit both at the same time.

    Code:
    <script type="text/javascript">
    function f1Submit()  {
    var n1 = document.f1.t1.value;
    var n2 = document.f2.t2.value;
    	if (!n1)  {
    		document.f2.t2.value = n2;
    		document.f2.action="/test2.php"
    		document.f2.submit();
    	}
    	else if (!n2)  {
    	document.f1.t1.value = n1;
    	document.f1.action="/test2.php"
    	document.f1.submit();
    	}
    	else if (n1 && n2){   //Submitting at the same time.
    		alert ("hello");
    	document.f1.t1.value = n1;
    	document.f2.t2.value = n2;
    	document.f1.action="/test2.php"
    	document.f2.action="/test2.php"
    	document.f1.submit();
    	document.f2.submit();
    	
    	}
    }
    function submitAll() {
    f1Submit();
    }                                                          
    </script>
    </HEAD>
    
    <BODY onload="document.f1.t1.focus();">
    <form name="f1" method="get"  enctype="multipart/form-data">
    
    F1 NAME: <input type="text" name="t1"  size="24"  />
    </form>
    
    <form name="f2" method="get"  enctype="multipart/form-data">
     
    F2 NAME: <input type="text" name="t2"  size="24"  />
    </form>
    
    <form name="allSubmit">
    <input type="button"  name="btn1"  value="Submit"  onClick="submitAll()" />
    </form>
    Thanks

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,078
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    This is not straightforward. You can only submit one form at a time as a browser window can't display two things in the same spot at the same time. If you want two things to happen then have the script that processes the first part of the form call a second script to process the rest of the form.


    Quizmaster: What colour is created by mixing red and yellow?
    Contestant: Green.
    Quizmaster: No, red and yellow.
    Contestant: Blue.

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there a way I use AJAX to submit two forms at once?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,078
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Yes. See:-

    http://9lessons.blogspot.com/2009/06...uery-ajax.html

    jQuery makes AJAX calls very simple so you shouldn't have any problem. Here is information on it: API/1.3/Ajax - jQuery JavaScript Library


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •