使用jQuery提交一个嵌套窗体的子窗体 [英] Submittng a child form in a nested form using jquery

查看:104
本文介绍了使用jQuery提交一个嵌套窗体的子窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < FORM METHOD =GETNAME =mainForm ACTION =<%= response.encodeURL( updateForm.jsp)%>> 

< / FORM>

< t:panel script =showSelect(3)>
< t:panelTab left =362width =200px> Tab3< / t:panelTab>
< t:panelBody src =childForm.jsp>
< / t:panelBody>
< / t:panel>

儿童表格代码:

 < FORM METHOD =GETNAME =childFormid =childFormACTION =<%= response.encodeURL(processChildForm.jsp)%>> 
< span style =padding:0 10px;>
< button class =submitChildFormClass
style =width:auto;
id =submitChildForm
>处理子表单
< / button>
< / span>
< / FORM>

我想提交子窗体,当我点击submitChildForm按钮时,我写了下面的jQuery处理程序这样做:

  $('。submitChildFormClass')。live('click',function(){
document .getElementById(previewOnlyVal)。value =previewOnly;
$('#childForm')。submit();
});

问题是,当我点击按钮时,主表单被提交而不是子表单。我知道使用嵌套表单并不是一个好的编程习惯,但这是一个旧代码,我们没有太多时间修改这些代码。
任何人都可以告诉我什么我可能会错过的代码,导致主表单由jQuery提交?在此先感谢您的帮助。

解决方案

不允许嵌套表单!你可以有几种形式,但不允许嵌套。


I have a nested form which looks something like:

    <FORM METHOD="GET" NAME="mainForm"  ACTION=<%=response.encodeURL("updateForm.jsp")%>>

    </FORM>

<t:panel script="showSelect(3)">
      <t:panelTab left="362" width="200px">Tab3</t:panelTab>
    <t:panelBody src="childForm.jsp">
    </t:panelBody>
</t:panel>

CHILD FORM CODE:

<FORM METHOD="GET" NAME="childForm"  id = "childForm" ACTION=<%=response.encodeURL("processChildForm.jsp")%>>
<span style="padding:0 10px;">
<button class="submitChildFormClass"
        style="width:auto;"
        id="submitChildForm"
        >Process Child Form
</button>
    </span>
</FORM>

I wanted to submit the child form when i click on submitChildForm button so I wrote the below jquery handler to do that:

$('.submitChildFormClass').live('click',function() {
    document.getElementById("previewOnlyVal").value = "previewOnly";
    $('#childForm').submit();
});

The problem is that when I click on the button, the MAIN FORM gets submitted instead of the child form. I know it isn't a good programming practice to use nested forms but this is an old code and we do not have much time yet to revise these codes. Can anyone tell me what I might be missing in the codes which causes the main form to be submitted by the jquery? Thanks in advance for your help.

解决方案

Nesting of forms is not allowed! you could have several forms but nesting is just not allowed.

这篇关于使用jQuery提交一个嵌套窗体的子窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆