4

I am submitting form via javascript by using 'document.FormName.submit()' . But this is giving me error of 'submit is not a function'. I m using IE8

<script typr="text/javascript">

function submitForm()
{
  document.theForm.submit()
}
</script>
<body>
<form name="theForm"  method="post">
<input type="text" name= "name">
<input type="button" name="submit" value="submit" onclick="submitForm()">
</form>
</body>

Please help me ?

Durga Dutt
  • 4,093
  • 11
  • 33
  • 48

7 Answers7

4

problem is with your button name

i have use this its work fine

<script type='text/javascript'>
function submitForm()
{
    document.theForm.submit();
}

</script>


<form name="theForm" method="post" action="default.php">
<input type="text" name="t" id="t"/><br/>
<input type="button" name="t1" value="submit" onClick="submitForm();">
</form>
Bhanu Prakash Pandey
  • 3,805
  • 1
  • 24
  • 16
0
document.getElementById("theForm").submit();

It works perfect in my case.

you can use it in function also like,

function submitForm()
{
     document.getElementById("theForm").submit();
} 

Set "theForm" as your form ID. It's done.

Chintan Thummar
  • 1,462
  • 19
  • 32
0

use

document.forms[index].submit()

instead

Amjad Masad
  • 4,035
  • 1
  • 21
  • 20
0

If your form name is FormName

try this

<a href="javascript:document.FormName.submit();">Action</a>

by the way your code is missing a semicolon at the end of the statement

and a spelling mistake here

<script typr="text/javascript">

typr

0

Try this:

document.getElementsByName("theForm")[0].submit();

And you need to put the script after you declared the elements so :

<form name="theForm" onSubmit= "submitForm()">
<input type="text" name= "name">
<input type="submit" name="submit" value="submit">
</form>

<script type="text/javascript">

function submitForm()
{
  document.getElementsByName("theForm")[0].submit();
}
</script>

Or you can use events like document onload if you want to kepp your scripts in the page head.

Luis
  • 5,979
  • 2
  • 31
  • 51
0

Here is the problem

change it typr is nothing should be type

<script typr="text/javascript">

to

<script language="javascript">

OR

<script type="text/javascript">
Shakti Singh
  • 84,385
  • 21
  • 134
  • 153
0

I just copy your code and executed in IE8 and it worked fine, so how is not working on your IE8. May be it is because of your hierarchy. So you please give id to form and try document.getElementById to access your form and then submit method. Do some thing like this"

<script type='text/javascript'>
    function submitForm()
    {
      document.getElementById('your_form').submit();
    }

</script>
   <form name="theForm" id="your_form" method="post" action="default.php">
      <input type="text" name="t" id="t"/>
      <input type="button" name="t1" value="submit" onClick="submitForm();">
   </form>
Hafiz
  • 4,187
  • 12
  • 58
  • 111