2011-10-07 59 views
3

我有一個struts 2表單標籤,我正在嘗試使用java腳本函數提交表單。但是當我嘗試執行此操作時,出現以下錯誤。提交不是js中的函數

"document.testForm.submit is not a function" IE 8(Object doesn't support this property or method) 

這裏是我的Java腳本功能和HTML代碼: -

<script type="text/javascript"> 
     function testFunction() 
     { 
      document.testForm.action = "testAction"; 
      document.testForm.submit(); 

     } 
</script> 

<s:form method="POST" id="fileForm" name="testForm" 
    enctype="multipart/form-data"> 
    <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
     <tbody> 
     <tr> 
      <td> 
      <input type="button" name="submit" value="Upload File" onclick="testFunction();"/> 
      </td> 
      </tr> 
     </tbody> 
    </table> 
</s:form> 

我使用FF 7和IE 8

請幫助我。

回答

22

的問題是,你命名你的提交按鈕「提交」:

<input type="button" name="submit" ...> 
<!--     ^^^^^^^^^^^^^ --> 

將其更改爲其它任何東西。表單元素使用其名稱添加爲表單對象的屬性,以便陰影(覆蓋)表單的內置submit屬性(這是您正在查找的功能)。

+1

哇!這很微妙。感謝那。 – bchurchill

+1

謝謝,保存了一天 –

2

我認爲你需要改變提交按鈕的名稱。將其更改爲name="Submit"或其他內容,然後重試。