Forum Moderators: open

Message Too Old, No Replies

how do I submit multiple <form>s with one submit?

         

partha

7:11 pm on Apr 20, 2005 (gmt 0)

10+ Year Member



I've tried a few JS examples I found on google but they didn't work.

Here's the problem:
I have form elements inside two different <div>s. So in order to do that, I had make each <div> have it's own <form> surround the form elements. But I want to be able to click ONE submit button and have it submit ALL the form elements on the page, as though they were all INSIDE THE SAME <form>.

any ideas?

orion_rus

10:05 am on Apr 21, 2005 (gmt 0)

10+ Year Member



i think it have same logical problems, your forms can have different actions and who should make first call, how html should know that second call should be done?
I think it's a bad idea to find ways to submit 2 forms at once. All what i can suggest you is to make a hidden fields in the second form hidden fields from the first, and in the first from the second. Then you sumbits one of the form, javascript before submitting fills this hidden fields and then submit all two forms in one.
You html would be like this:
<form name='form1' action='process.php' onsubmit=somefunction() >
<input type='text' name='username' id='username1' />
<input type='hidden' name='surname' id='surname1'/>
</form>

<form name='form2' action='process.php' onsubmit=somefunction2() >
<input type='hidden' name='username' id='username2' />
<input type='text' name='surname' id='surname2' />
</form>

I hope this helps you
Good luck!

ajkimoto

10:21 pm on Apr 21, 2005 (gmt 0)

10+ Year Member



partha,

I am somewhat confused by your post:

I have form elements inside two different <div>s. So in order to do that, I had make each <div> have it's own <form> surround the form elements

Why would you have to do this? You can certainly wrap both divs in a single form:

<form method="post" action="duh.htm">
<div id="div1">
<input type="text" size="20" id="txtOne" name="txtOne" />
</div>
<div id="div2">
<input type="text" size="20" id="txtTwo" name="txtTwo" />
</div>
</form>

If there is some other reason for needing two forms, you could put each form on a separate html page and put each page in an iframe on a container page. That way you could have one button on the container page submit the forms in each of the documents contained in the iframes.

ajkimoto