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 ?

3
  • its work fine for me check that your javascript Commented Dec 31, 2010 at 5:33
  • Why are you attempting to submit the form again after is has been already submitted? Basically, why are calling the submit through JavaScript in the onsubmit event which means that the form is already submitted Commented Dec 31, 2010 at 5:40
  • possible duplicate of Form not submitting with JS Commented Apr 14, 2014 at 8:20

7 Answers 7

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>
Sign up to request clarification or add additional context in comments.

Comments

0

use

document.forms[index].submit()

instead

Comments

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.

Comments

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

Comments

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

Comments

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>

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.