小编典典

提交隐藏的表单HTML

jsp

当在另一个表单的一部分的文本输入字段中输入值时,我想提交隐藏表单。

<form name="TDISLabelForm" target="fr1" method='POST' action="/createLabelTDIS.do">
                <input type="hidden" name="lab_no" value="<%=lab_no%>">
                <input type="hidden" name="accessionNum" value="<%=accessionNum%>">
                <input type="hidden" id="label" name="label" value="<%=label%>">

    </form>  
<iframe style="height:1px;width:1px;border:none:" id="fr1"></iframe>
<form name="ackForm" method="post" action="/UpdateStatus.do">

            <button type="button" value="Label">Label</button>
             <input type="text" id="label" name="label" value="<%=label%>"/>
             <input type="button" onclick="TDISLabelForm.submit()" value="Create">

 </form>

当我单击提交TDISLabelForm的“创建”按钮时,我想提交“标签”的值。如何才能做到这一点?

谢谢你的帮助。


阅读 849

收藏
2020-06-10

共1个答案

小编典典

这是一个开始,让您上路http://en.wikipedia.org/wiki/XMLHttpRequest

function submitLable(lblval){
   var payLoad = document.forms['TDISLabelForm']
                         .lab_no.value = document.forms['ackForm']
                         .label.value; // pass the value for visible for to the hidden form
   var request = requestObject();
   request.open("POST", "/createLabelTDIS.do", false); // post the value to createLabelTDIS.do for further processing as usual.
   request.send(payLoad);
}


function requestObject() {
   if (window.XMLHttpRequest)
      return new XMLHttpRequest();
   else if (window.ActiveXObject)
      return new ActiveXObject("Msxml2.XMLHTTP");
   else
      throw new Error("Could not create HTTP request object");
}

<input type="button" onclick="submitLable(this)" value="Create">
2020-06-10