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.
source share