使用单个提交按钮和Ajax在JSP中提交两个HTML表单

编程入门 行业动态 更新时间:2024-10-27 14:29:34
本文介绍了使用单个提交按钮和Ajax在JSP中提交两个HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的页面设计是这样的,我必须使用两种表单,这些表单只需单击一下即可提交,然后保存到数据库中,反之亦然. 我在Struts2 Framework的JSP页面上使用了它 我已经尝试过Ajax解决方案,但是它们对我不起作用.

My page design is such that I have to use two forms that submit on single click and then saved to database and vice verse. I am using this on a JSP page with Struts2 Framework I have tries the Ajax solutions but they are not working for me.

这是我的脚本(已更新):

$("#visitType").buttonset(); $("#patientCondition").buttonset(); $("input[type=submit], a, button").button().click(function(event) { event.preventDefault(); var inputs=$('#visitType,#patientCondition ').find(':input').not(this); var form_data={}; inputs.each(function(){ form_data[this.name]=$(this).val(); }); $.post('patientSoapAll', form_data, function(response){ }); });

我的表格1:

<s:form action="PatientSoapAll" method="post"> <div id="visitType"> <input type="radio" id="I" value="I" <s:if test='pSB.rOS == "I"'>checked</s:if> name="pSB.rOS" /><label for="I">I V</label> <input type="radio" id="R" value="R"<s:if test='pSB.rOS == "R"'>checked</s:if>name="pSB.rOS" /><label for="R">Regular Visit</label> <input type="radio" id="P/N" <s:if test='pSB.rOS == "P/N"'>checked</s:if>name="pSB.rOS" /><label for="D/N">Re- Evaluation</label> <input type="radio" id="D/N"<s:if test='pSB.rOS == "D/N"'>checked</s:if> name="pSB.rOS" /><label for=" P/N">Discharge</label> </div> </s:form>

我的表格2:

<s:form action="PatientSoapAll" method="post"> <div id="patientCondition"> <input type="radio" id="new" value="n"<s:if test='pSB.r2 == "n"'>checked</s:if> name="pSB.r2" /> <label for="new">New</label> <input type="radio" id="noChange" value="nC" <s:if test='pSB.r2 == "nC"'>checked</s:if> name="pSB.r2" /><label for="noChange">No Change</label> <input type="radio" id="progressing" value="p"<s:if test='pSB.r2 == "p"'>checked</s:if> name="pSB.r2" /><label for="progressing">Progressing</label> <input type="radio" id="notProgressing" value="nP" <s:if test='pSB.r2 == "nP"'>checked</s:if> name="pSB.r2" /><label for="notProgressing">Not Progressing</label> </div> </s:form>

这是我的已更新的提交"按钮.从Div中删除并放置在表格中.

<tr> <td></td> <td><input type="submit" value="Save Note" /></td> </tr>

我正在使用struts 2,并且我想将此提交按钮重定向到一个操作PatientSoapAll,我正在使用.do的自定义扩展名而不是.action(默认情况下).请告诉我如何将该提交按钮重定向到struts2中的相应操作类.

I am using struts 2 and I want to redirect this submit button to an action patientSoapAll, I am using custom extension of .do instead of .action(by default). Please tell me how can I redirect this submit button to respective action class in struts2.

推荐答案

找到了一个简单的解决方案.

Found an easy solution to it.

javascript:

javascript:

submitForms = function() { $('#form2 :input').not(':submit').clone().hide().appendTo('#form1'); document.getElementById("form1").submit(); };

提交按钮:

<input type="button" value="Save Note" onclick="submitForms()" />

更多推荐

使用单个提交按钮和Ajax在JSP中提交两个HTML表单

本文发布于:2023-10-11 13:54:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1481888.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   按钮   两个   JSP   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!