Anshul
Anshul

Reputation: 645

Submit is not a function in js

I have a struts 2 form tag,i am trying to submit the form using the java script function.But when i try to do this i am getting the following error.

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

Here is my java script function and html code:-

<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>

I am using FF 7 and IE 8

Please help me out.

Upvotes: 3

Views: 6338

Answers (2)

T.J. Crowder
T.J. Crowder

Reputation: 1074969

The problem is that you've named your submit button "submit":

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

Change it to just about anything else. Form elements get added as properties to the form object using their names, so that shadows (overrides) the form's built-in submit property (which is the function you're looking for).

Upvotes: 22

Skyline
Skyline

Reputation: 63

I think you need to change the name of your submit-button. Change it to name="Submit" or something else and try again.

Upvotes: 2

Related Questions