Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In short: change the <strong>id</strong> of your submit button to something different than "submit". Also, don't set the <strong>name</strong> to this value either.</p> <p>Now, some deeper insight. The general case is that <code>document.formname.submit</code> is a method that, when called, will submit the form. However, in your example, <code>document.formname.submit</code> is not a method anymore, but the DOM node representing the button.</p> <p>This happens because elements of a form are available as attributes of its DOM node, via their <code>name</code> and <code>id</code> attributes. This wording is a bit confusing, so here comes an example:</p> <pre><code>&lt;form name="example" id="example" action="/"&gt; &lt;input type="text" name="exampleField" /&gt; &lt;button type="button" name="submit" onclick="document.example.submit(); return false;"&gt;Submit&lt;/button&gt; &lt;/form&gt; </code></pre> <p>On this example, <code>document.forms.example.exampleField</code> is a DOM node representing the field with name "exampleField". You can use JS to access its properties such as its value: <code>document.forms.example.exampleField.value</code>.</p> <p>However, on this example there is an element of the form called "submit", and this is the submit button, which can be accessed with <code>document.forms.example.submit</code>. This overwrites the previous value, which was the function that allows you to submit the form.</p> <p><strong>EDIT:</strong></p> <p>If renaming the field isn't good for you, there is another solution. Shortly before writing this, I left the question on the site and got a response in the form of a neat JavaScript hack:</p> <pre><code>function hack() { var form = document.createElement("form"); var myForm = document.example; form.submit.apply(myForm); } </code></pre> <p>See <a href="https://stackoverflow.com/questions/1999891/how-to-reliably-submit-an-html-form-with-javascript">How to reliably submit an HTML form with JavaScript?</a> for complete details</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload