flyingknight
asked on
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.
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.
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
<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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> 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".
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.
-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].elem ents.lengt h; loop2 ++)
{
//increment element counter
elementCounter++;
//add the element to form[0]
document.forms[0].appendCh ild(docume nt.forms[l oop1].elem ents[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="makeAndSubmitTheB igForm();" >
</BODY>
</HTML>
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].elem
{
//increment element counter
elementCounter++;
//add the element to form[0]
document.forms[0].appendCh
}
}
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="makeAndSubmitTheB
</BODY>
</HTML>
Another possibility might be the creative use of CSS positioning.
eg.
<form name=bigForm>
<form name=inForm>
<input type=submit name=iSub value=submit>
</form>
<input type=submit name=bSub value=submit>
</form>