Solved

2 forms on one html page - how?

Posted on 2003-11-18
7
249 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Web experts ! HTML ! Javascript project for medical MRI sharing 24 49
Hide Table in merge 3 29
parse url to form? 7 25
How to create a table with buttons 3 21
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

790 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