Solved

2 forms on one html page - how?

Posted on 2003-11-18
7
245 Views
Last Modified: 2010-04-09
i have one form which spans from the top of my page to the bottom and within that another small form. prob is when i have them both on the same page and u hit either submit button, its not posting the right action. ie: form 1 on submit posts to the address of form 2. what tags would i put in to make sure they go to the correct urls of each.

big form

<form method="post" action="http://www.dfg/order.asp" onsubmit="return validateForm(this)" id=form1 name=form1>

-----------------
small form within above form tags

<form action="mailinglist.cgi" method="post">
  <input type="hidden" name="action" value="subscribe">

pls show exactly where code goes. thanks.
0
Comment
Question by:flyingknight
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 5

Expert Comment

by:ho_alan
ID: 9776207
u may rename the submit button, see if it helps.

eg.

<form name=bigForm>
<form name=inForm>
<input type=submit name=iSub value=submit>
</form>
<input type=submit name=bSub value=submit>
</form>
0
 
LVL 2

Expert Comment

by:incongruent
ID: 9776413
I haven't tested this code, but I think it should do the trick:  note that you use input type=button and not input type=submit.


<head>
<script language=Javascript>
function submitThis(whichOne)
{
  if(whichOne=='outer')
     document.form1.submit();
  else if(whichOne =='inner')
     document.form2.submit();
}
</script>
</head>
<body>
<form method="post" action="http://www.dfg/order.asp" onsubmit="return validateForm(this)" id=form1 name=form1>
..
..
<input type="button" name="goForm1" value="Submit Outer" onClick="submitThis('outer');">
..
..
<!--use input type=button instead of input type submit for both forms-->
<form action="mailinglist.cgi" name=form2 method="post">
  <input type="hidden" name="action" value="subscribe">
  <input type="button" name="goForm2" value="submit" onClick="submitThis('inner');">


-Allan
0
 
LVL 5

Expert Comment

by:ho_alan
ID: 9776463
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Accepted Solution

by:
monvelasquez earned 155 total points
ID: 9776874
so you're saying that the small form is WITHIN the bigger form?
in that case, the action of the smaller form overrides that of the larger form.

you should not put another form inside a form (i.e. nesting)...
you should separate your forms...
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9777426
> in that case, the action of the smaller form overrides that of the larger form.

Ummm....... No.

In that case the behaviour is undefined, because forms cannot contain other forms. Period.

Check the HTML spec:

  <!ELEMENT FORM - - (%block;|SCRIPT)+ -(FORM) -- interactive form -->

(Translation for those of you who don't speak DTD: "FORM may contain block elements and/or SCRIPT blocks. It may not contain other FORM elements.")

So it's not a case of "should not nest", it's a case of "MUST not nest".
0
 
LVL 2

Expert Comment

by:incongruent
ID: 9777738
Well you heard it from Zontar,

you can't do that.


But if your problem exists because you need your 'outer' form spanning most of the page,  you could probably split it into multiple forms and collect them into then submit the merged one.  

I just tested this script and it seems to work by adding all the elements to the first form tag.  This may 'ugly up' your page on submit though.  



-Allan

--code as follows--

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function makeAndSubmitTheBigForm()
{
//form[0] will be the big form....


//countAllElements
var elementCounter=0;

  //start at form[1] and add all elements to form[0]
  for ( var loop1=1; loop1 < document.forms.length; loop1 ++)
  {
      for ( var loop2=0; loop2 < document.forms[loop1].elements.length; loop2 ++)
          {
                 //increment element counter
                 elementCounter++;

                 //add the element to form[0]
                 document.forms[0].appendChild(document.forms[loop1].elements[loop2]);
               }
   }
 
  document.forms[0].submit();

}</script>
</HEAD>

<BODY>
<form action="none" method="get">
</form>

<form name=1>
<input type=text name=abc value="WOW">
</form>
<form name=2>
<input type=text name=def value="WOW">
</form>
<form name=3>
<input type=text name=ghi value="WOW">
</form>

<input type=button name=click value=click onclick="makeAndSubmitTheBigForm();">

</BODY>
</HTML>
0
 
LVL 11

Expert Comment

by:Zontar
ID: 9779187
Another possibility might be the creative use of CSS positioning.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bootstrap 3 application structure 7 45
Popup to change image and store url in database 2 31
Problem with a CSS in a page 2 26
Form Submit falis 6 26
Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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