Solved

How do I submit multiple forms with one action call

Posted on 2001-08-10
12
438 Views
Last Modified: 2010-05-18
I have two forms that I need to submit at the same time.  How can I do this?
0
Comment
Question by:97g8r
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6372639
As far as I know you cannot submit two forms at the same time if you're planning to do it on the same page? Why because the browser can only go to one place at a time. However, if you wish to submit the two forms and they don't necessarily need to display anything once done then you can create popup windows for the forms and then put a check in each one that once completed causes them to close and take your original browser to another predetermines page (that perhaps tells you what has happened).

Hope that kind of makes sense.

Regards,
CyberSoft
0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6372663
Here's an example why it won't work. Try it out for yourself. It will try and first go to www.yahoo.com (where the first form submits to) and then tryand go to www.cnn.com (where the second form submits) to.

But the last form being submitted is the one that the browser will attempt to go to. As soon as the second submit line is called and the browser hasn't already reached www.yahoo.com that navigation is cancelled and the browser then goes to www.cnn.com

<!-- start code -->

<html>
<head>
     <title>Submit two forms at same time</title>
     <script language="JavaScript">
     function submitForms()
     {
          document.frm1.submit()
          document.frm2.submit()
     }
     </script>
</head>

<body>

<form id="frm1" name="frm1" method="post" action="http://www.yahoo.com/">
     <input type="hidden" name="hiddenField1" value="dummy">
</form>

<form id="frm2" name="frm2" method="post" action="http://www.cnn.com/">
     <input type="hidden" name="hiddenField1" value="dummy">
</form>

<form id="frmSubmit" name="frmSubmit">
     <input type="button" name="submit" value="submit both forms" onclick="submitForms();">
</form>

</body>
</html>

<!-- end code -->
0
 
LVL 2

Expert Comment

by:MCM
ID: 6373285
In CyberSoft's example, the 1st submit request may be sent to yahoo. So, if you were trying to update a database with the contents of the first form and of the second form, the 1st submit request might have the desired effect, even though the browser would never see the response.

That said, though, sending two requests at once is not what browsers were designed to do -- so even if you found a double-submit trick that worked, it would be a cluge. Why is it so important to have two forms? It's hard to imagine a situation where this is totally necessary. Maybe you could describe what you are trying to do more generally, and someone can propose an alternative method for dealing with the problem.
0
 
LVL 1

Expert Comment

by:isarana
ID: 6373628
You could try combining 2 forms and submit as one form by having a third form with invisible fields, copy the contents of the first two forms and submit...


<SCRIPT LANGUAGE="JavaScript"><!--
  function copydata() {
      document.formC.one.value = document.formA.one.value;
      document.formC.two.value = document.formB.two.value;
      document.formC.submit();
      return false;
  }
  //--></SCRIPT>

  <FORM NAME="formA" onSubmit="return copydata()">
  Enter your text 1: <INPUT TYPE="text" NAME="one">
  <P><INPUT TYPE="BUTTON" VALUE="Submit" onClick="copydata()">
  </FORM>

  <FORM NAME="formB" onSubmit="return copydata()">
  Enter text 2: <INPUT TYPE="text" NAME="two">
  <P><INPUT TYPE="BUTTON" VALUE="Submit" onClick="copydata()">
  </FORM>

  <FORM NAME="formC">
  <INPUT TYPE="HIDDEN" NAME="one">
  <INPUT TYPE="HIDDEN" NAME="two">
  </FORM>
0
 
LVL 1

Expert Comment

by:labcoat
ID: 6374069
isarana's comment will definately work if both forms are being submitted to the same URL and the server-side code is set up to accept the two forms as one.

--labcoat
0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6374438
I assumed since 97g8r wabted two separate forms to be submitted that their content was not related and they needed to be submitted to different pages for processing - hence I didn't provide a combined form solutoin as isarana did.

97g8r - can you give us more info?

Regards,
CyberSoft
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 1

Expert Comment

by:labcoat
ID: 6374898
CyberSoft, that is probably the case.

You could also submit the forms to two seperate server-side pages in two seperate hidden iframes in the newer browsers (similar to the popup window comment above).

--labcoat
0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 6375172
Labcoat, that's a good idea as well - didn't think about hidden frames when I wrote the popup windows as a solution.

Wonder if 97g8r is even reading this thread since he/she hasn't responded since their original post?

Regards,
CyberSoft
0
 
LVL 12

Expert Comment

by:ahosang
ID: 7960768
This question has been abandoned. I will make a recommendation to the moderators on its resolution in a week or two. I appreciate any comments that would help me to make a recommendation.
 
In the absence of responses, I may recommend DELETE unless it is clear to me that it has value as a PAQ. Silence = you don't care
 
ahosang
0
 
LVL 12

Expert Comment

by:ahosang
ID: 8021319
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQ - NO REFUND
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
ahosang
EE Cleanup Volunteer
0
 
LVL 3

Expert Comment

by:CyberSoft
ID: 8032087
I guess isarana, labcoat and myself put pretty much equal effort into this question? Split points? Suggestions?

Regards,
Cybersoft
0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 8092575
Cybersoft,

In the absence of comments from the asker, it's impossible to tell which comment might have helped. While it's my own PERSONAL opinion that effort should be rewarded, as a Moderator/Admin, we're not in a position to do that.

Per recommendation, points NOT refunded and question closed.

Netminder
EE Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now