2011-10-11 130 views
2

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

<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的创建按钮。如何才能做到这一点?

感谢您的帮助。

+0

您需要如果我明白你想要做什么使用AJAX。 –

+0

我之前没有使用过AJAX ...你能给我一个线索我怎么能做到这一点? – Sapphire

+0

如果可以的话,请自己做个大忙,并使用像jQuery这样的JS库。 http://api.jquery.com/jQuery.ajax/ –

回答

2

这是一个开始,让你对你的方式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"> 
+0

非常感谢。这工作! – Sapphire

+0

无后顾之忧 – david