2011-10-11 82 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