Problem in submit form via javascript

I submit the form via javascript using 'document.FormName.submit ()'. But that gives me a "submit is not a function" error. I am 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?

+4
source share
7 answers

problem with your button name

I use this feature perfectly

 <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> 
+4
source

use

 document.forms[index].submit() 

instead

0
source

If your form name is FormName

try it

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

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

and spelling mistake here

 <script typr="text/javascript"> 

typr

0
source

Try the following:

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

And you need to put the script after you declared the elements like this:

 <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 rewrite your scripts in the page header.

0
source

Here is the problem

change it typr, nothing should be printed

 <script typr="text/javascript"> 

to

 <script language="javascript"> 

OR

 <script type="text/javascript"> 
0
source

I just copied your code and executed it in IE8, and it worked fine, as it doesnโ€™t work on your IE8. Maybe this is because of your hierarchy. So please give an id to create and try document.getElementById to access your form and then submit the method. Do something like that. "

 <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> 
0
source
 document.getElementById("theForm").submit(); 

It works great in my case.

you can also use it in a function,

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

Set "theForm" as the form identifier. It's done.

0
source

Source: https://habr.com/ru/post/1333871/


All Articles