Submit two HTML forms in JSP using single submit button with Ajax

久未见 提交于 2019-12-01 12:21:53

You can use Struts2 jQuery to submit multiple forms

<sj:submit formIds="visitType,patientCondition" targets="result" value="Submit" />  

formIds:

Comma delimited list of form ids for which to serialize all fields during submission when this element is clicked (if multiple forms have overlapping element names, it is indeterminate which will be used)

Found an easy solution to it.

javascript:

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

Submit button :

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

You can use jQuery .serialize to do what you want. Give some class to your forms then use it to select your forms and call serialize to get a string in the standard URL-encoded notation. After that you can use some AJAX method to post it to your action.

$(function() {
  $("#saveNoteButton").click(function() {
    alert($(".forms").serialize());
  });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!