如何在一个页面中用按钮提交另一个页面的表单 ( 积分: 50 )

  • 主题发起人 主题发起人 miles^o^
  • 开始时间 开始时间
M

miles^o^

Unregistered / Unconfirmed
GUEST, unregistred user!
公司要我用jsp接着前人做一个东西,当前是这样的:在一个页面payer_regist里onload了另一个页面payer_regist_iframe。在payer_regist中有一个按钮,在payer_regist_iframe中有一个表单,我要用payer_regist里的按钮提交payer_regist_iframe的表单内容到一个servlet去处理,怎么办?请大家多多指教。多谢多谢
 
公司要我用jsp接着前人做一个东西,当前是这样的:在一个页面payer_regist里onload了另一个页面payer_regist_iframe。在payer_regist中有一个按钮,在payer_regist_iframe中有一个表单,我要用payer_regist里的按钮提交payer_regist_iframe的表单内容到一个servlet去处理,怎么办?请大家多多指教。多谢多谢
 
不知道和普通网页是不是一样
window.frames[0].forms[0].submit;// 提交对应的Form的内容
前面的0是你来定的,看是第几个frame,用name也可以,后面的0是play_list_iframe里面的form需要,用id和name都可以
个人看法,仅供参考
 
感谢chenybin兄,确实可以实现传递了,但是出现了一个新问题,我这样写的
<a href=&quot;javascript:void(window.tab_iframe.postcode.submit())&quot;>
结果,因为是对tab_iframe(即play_regist_iframe叶面的frame名)进行操作,结果,当我返回结果叶面payer_list.html(在servlet中用转向)时,把payer_list.html放在了play_regist_iframe的位置显示!也就是说,现在的返回结果是一个play_regist叶面中嵌套了一个payer_list叶面!可我要的是单独显示payer_list.html叶面阿,怎么办呢?
 
看一下Frame的target设置,另外你放的是image吗?不用<a herf> 用onclick,设置一下target,多弄几次就出来了
 
先声明一下,我把上面的叶面名给了几处,打错了。我要不行了,改了若干次,没出来。*_* ,我不知道target 和 onclick怎么用...不要鄙视我...注意了一下,payer_regist_iframe里没看到<frameset>payer_regist_iframe开头代码是这样的
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=Shift_JIS&quot;>
<title>請求先新規登録</title>
<link href=&quot;css/style.css&quot;
rel=&quot;stylesheet&quot;
type=&quot;text/css&quot;>
<script language=&quot;JavaScript&quot;>
<!--
function houjingrp_search() {
window.open(&quot;payer_houjingrp_list.html&quot;,&quot;print&quot;, &quot;left=0, top=0, status=no, resizable=1, scrollbars=1, toolbar=1, menubar=1&quot;);
}
function houjingrp_regist(mode) {
if( mode==&quot;1&quot;
){
document.all.show_regist.style.display = &quot;Block&quot;;
}
else
{
document.all.show_regist.style.display = &quot;none&quot;;
}
}
function postcode_search() {
window.open(&quot;payer_postcode_list.html&quot;,&quot;print&quot;, &quot;left=0, top=0, status=no, resizable=1, scrollbars=1, toolbar=1, menubar=1&quot;);
}
//-->
</script>
</head>
<body class=&quot;
iframe1&quot;
>
<form name=&quot;postcode&quot;
action=&quot;InputServlet&quot;
method=&quot;get&quot;>
<table width=&quot;100%&quot;
border=&quot;0&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;
class=&quot;listpage&quot;
height=&quot;100%&quot;>
payer_regist相关的是这样的:
......
<body onLoad=&quot;LoadTab('payer_regist_iframe.html')&quot;>
<form action=&quot;InputServlet&quot;
name=&quot;regist&quot;
method=&quot;post&quot;>
......
<iframe src=&quot;payer_regist_iframe.html&quot;
onreadystatechange=&quot;frmop();&quot;
height=&quot;460&quot;
width=&quot;100%&quot;
border=&quot;0&quot;
marginheight=&quot;0&quot;
marginwidth=&quot;0&quot;
frameborder=&quot;0&quot;
hspace=&quot;0&quot;
vspace=&quot;0&quot;
SCROLLING=&quot;auto&quot;
name=&quot;tab_iframe&quot;
></iframe>
</td>
</tr>
</table>
</td>
</tr>

<tr>
<td class=&quot;subtitleTD&quot;
colspan=&quot;2&quot;><div align=&quot;right&quot;>
<table border=&quot;0&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;>
<tr id=&quot;btn1&quot;
style=&quot;display:Block&quot;>
<!-- <td><a href=&quot;payer_list.html&quot;><img src=&quot;img/regist2_btn.gif&quot;
width=&quot;78&quot;
height=&quot;26&quot;
border=&quot;0&quot;></a></td>
<td><input type=&quot;Image&quot;
name=&quot;submit&quot;
src=&quot;img/regist2_btn.gif&quot;
width=&quot;78&quot;
height=&quot;26&quot;
border=&quot;0&quot;
onclick =&quot;sub(this.form)&quot;></td>
-->
<td><a href=&quot;javascript:void(window.tab_iframe.postcode.submit())&quot;><img src=&quot;img/regist2_btn.gif&quot;
width=&quot;78&quot;
height=&quot;26&quot;
border=&quot;0&quot;></a></td>
 
<td><input type=&quot;Image&quot;
name=&quot;submit&quot;
src=&quot;img/regist2_btn.gif&quot;
width=&quot;78&quot;
height=&quot;26&quot;
border=&quot;0&quot;
onclick =&quot;sub(this.form)&quot;></td>
-->
<td><a href=&quot;javascript:void(window.tab_iframe.postcode.submit())&quot;><img src=&quot;img/regist2_btn.gif&quot;
width=&quot;78&quot;
height=&quot;26&quot;
border=&quot;0&quot;></a></td>
上面那个就是onclick的,你参考一下,不过好像关系不大,先试下

我的意思是在payer_regist_iframe.html的佛如没那里设置这里设置一下target,
<form name=&quot;xxx&quot;
target=&quot;_self&quot;
method=&quot;xxx&quot;
action=&quot;xxx&quot;>
具体记不得了,好久没弄了,自己测一下
参考网址
http://w269.com/infow269/379w2691.htm
http://51js.zahui.net/html/1/30100.htm
 
谢谢,搞定了,最后是这样做的
payer_regist
<script language=&quot;JavaScript&quot;>
function input(form1,form2)
{ form1.action=&quot;InputServlet&quot;;
form2.action=&quot;PayerListShow&quot;;
form1.submit();
form2.submit();
}
<script>
.....
<td><input type=&quot;Image&quot;
name=&quot;submit&quot;
src=&quot;img/regist2_btn.gif&quot;
width=&quot;78&quot;
height=&quot;26&quot;
border=&quot;0&quot;
onclick =&quot;input(window.tab_iframe.postcode,this.form)&quot;></td>
多添了一个servlet: PayerListShow。把原来InputServlet里的内容分成两部分,一部分专门向数据库写入,由iframe里的form提交。另一部分专门写查询全部数据并转向新叶面,由主页面的form提交转向。没有写target,另外,没有如果不分开的话,虽然也能实现要求,但是由于主页面提交了一个空表单,会导致两次写入数据库,其中一次失败并报警。
最后再次感谢chenybin兄!结贴,放分,恩。
 
接受答案了.
 
后退
顶部