2011-10-07 63 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"或其他内容,然后重试。