Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

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.
0
flyingknight
Asked:
flyingknight
  • 2
  • 2
  • 2
  • +1
1 Solution
 
ho_alanCommented:
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
 
incongruentCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
monvelasquezCommented:
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
 
ZontarCommented:
> 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
 
incongruentCommented:
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
 
ZontarCommented:
Another possibility might be the creative use of CSS positioning.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now