Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy Form Elements should not be named submit?
    primarykey
    data
    text
    <p>I figured out through debugging that I should not name any Form Elements <code>name="submit"</code>, but even after searching I didn't find any good explanation of why?</p> <p>See simple code example below:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="javascript:alert('submitted');" method="post" id="test-form"&gt; &lt;label&gt;Name&lt;/label&gt; &lt;input type="text" name="name-field" value="" /&gt; &lt;input type="submit" name="submit" value="Submit Button" /&gt; &lt;!-- name should not be "submit" --&gt; &lt;p&gt;&lt;a href="javascript: document.getElementById('test-form').submit();"&gt;Submit Link&lt;/a&gt;&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <ul> <li>If you <strong>Press Enter</strong> while on any Form Element or <strong>Click</strong> the <em>Submit Button</em>, it will work.</li> <li><p>If you <strong>Click</strong> on the <em>Submit Link</em>, it will have error</p> <p>Unhandled Error: 'document.getElementById('test-form').submit' is not a function</p></li> </ul> <p>If you simply <strong>rename</strong> your <em>Submit Button</em> to anything other than <code>name="submit"</code> (even if you just capitalize some part of it) or just <strong>remove</strong> the <code>name="submit"</code> attribute, then both the <em>Submit Button</em> and <em>Submit Link</em> will work.</p> <p>I tried this in the latest version of Internet Explorer, Firefox, Opera, Chrome, and Safari. All of them have consistent behavior with regards to this.</p> <p>As you can see in my code example, there is no involvement of jQuery or any other JavaScript library.</p> <p>I would appreciate the explanation. Thanks</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. 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