1

I am trying to use the javascript .submit() to auto submit a form, however one of the fields has a name called submit so it returns.

TypeError: document.forms.go.submit is not a function
[Break On This Error]   

document.forms["go"].submit();

Is there anything I can use apart from .submit

h00j
  • 308
  • 1
  • 7
  • 18

1 Answers1

1

The best solution is to use a name that doesn't cause a conflict.

You may, however, be able to invoke submit via the prototype. For example,

HTMLFormElement.prototype.submit.call( // invoke form submit on
    document.forms["go"] // your form
);

Similarly you could try to "borrow" it from another <form>

document.createElement('form').submit.call( // invoke submit from another form on
    document.forms["go"] // your form
);

These are more hacks than real solutions, so you should really consider choosing a different name.

Paul S.
  • 64,864
  • 9
  • 122
  • 138
  • Browsers are not required to implement any kind of inheritance, much less prototype inheritance so I would not suggest attempting to use this approach. – RobG Jun 03 '13 at 00:21
  • @RobG true, but that doesn't mean it's never available. Added a second "hack" which does a similar thing. I made it even stronger that removing the name conflict is the better choice, too, in case it wasn't strong enough before. – Paul S. Jun 03 '13 at 01:11
  • That's no better, host objects don't have to implement call, though I'm surprised that IE 8 seems to. :-) – RobG Jun 03 '13 at 01:20