21

Possible Duplicate:
submit is not a function in javascript

Why is the following basic javascript function giving me an error document.getElementById("form").submit is not a function.

The only thing i have on a page is a form and this javascript function. I want he form to auto submit when page is accessed.

<script>
 window.onload = function(){
 document.getElementById('form').submit();
}
</script>
Community
  • 1
  • 1
Pinkie
  • 10,126
  • 22
  • 78
  • 124

2 Answers2

69

Make sure that there is no name="submit" or id="submit" in the form

Naftali
  • 144,921
  • 39
  • 244
  • 303
20

This is probably because the form contains input with name=submit; then the submit property contains object of the element. Rename it or use

document.createElement('form').submit.call(document.getElementById('form'));
duri
  • 14,991
  • 3
  • 44
  • 49