同一个页面多个form

<!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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值