Technical stuff Requirements are like water. They're easier to build on when they're frozen.

Form submit from JavaScript

01.16.2009 · Posted in News

Be careful: if you want to submit a form from Javascript using something like

this.form.submit();

or

document.forms[ myFormName ].submit();

and it gives you a nasty error like

submit is not a function

don’t despair, just:

  • look at the HTML source code:
    <input id="submit" name="submit" value="Send to developer" type="submit"  />
    
  • change the name of the button to something else, like:
    <input id="mySubmitButton" name="mySubmitButton" value="Send to developer" type="submit" />
    

That’s all!

Now the explanation: the browser confuses your submit(); call with the button object, which has no such action.

The browser acted just like you were explicitly calling

button = document.getElementById( 'submit' );
button.submit();

One Response to “Form submit from JavaScript”

  1. [...] Form submit from JavaScript (tekkie.ro) [...]

Leave a Reply