2 forms on one html page - how?

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.
Who is Participating?
monvelasquezConnect With a Mentor Commented:
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...
u may rename the submit button, see if it helps.


<form name=bigForm>
<form name=inForm>
<input type=submit name=iSub value=submit>
<input type=submit name=bSub value=submit>
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.

<script language=Javascript>
function submitThis(whichOne)
  else if(whichOne =='inner')
<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');">

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

> 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".
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.  


--code as follows--

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

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

                 //add the element to form[0]


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

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

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

Another possibility might be the creative use of CSS positioning.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.