欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

同一个页面多个form

程序员文章站 2022-04-07 21:01:01
...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<style type="text/css">
</style>
<SCRIPT LANGUAGE="JavaScript">
var formSubmit = function(obj){
    var formObj = obj.parentNode;
    while(formObj.nodeName.toLowerCase() != "form"){
        formOb = formObj.parentNode;
    }
    formObj.submit();
}
</SCRIPT>
</HEAD>
<BODY>
<FORM action="a.html">
<A onclick="formSubmit(this)">提交1</A>
</FORM>
<FORM action="b.html">
<A onclick="formSubmit(this)">提交2</A>
</FORM>
</BODY>
</HTML>


Actually, it is possible to submit multiple forms, as long as the target for each form is different.

Like this...

<form id='form1' name='form1' action='firsttarget.htm' target='_blank' method='POST'> 
--your form fields--
</form>
<form id='form2' name='form2' action='secondtarget.htm' target='_self' method='POST'> 
--your form fields--
</form>

Then, rather than a submit button, a link like this...
<a href='javascript:doit()'>Click Here To Submit Both Forms</a>

And in the header...
<script language='javascript'>
<!--
function doit()
{
document.form1.submit();
document.form2.submit();
}
-->
</script>

When you click, it will submit the first form to a page that opens in a new window, and the second form to a page that opens in the current window.

Or you could use iframes... 
<iframe name='if1' id='if1' src='firsttarget.htm' border='0' frameborder='0' scrolling='auto' width='240' height='680'></iframe>
<iframe name='if2' id='if2' src='secondtarget.htm' border='0' frameborder='0' scrolling='auto' width='240' height='680'></iframe>

And in the forms, target='if1' and target='if2' respectively.

In this case, when you click the submit link, it will send the data from the two different forms to the two iframe areas on your page.

The only caution is that your field names in both forms must be unique... that is, you can't have name='firstname' in the first form, and name='firstname' in the second form too.

I hope this helps.

转载于:https://my.oschina.net/u/138995/blog/199773