parsley form not submitting when submit button has name=“submit”

妖精的绣舞 提交于 2019-12-18 09:08:21

问题


I just discovered that my form isn't submitting when i give the submit element the name="submit" attribute. When I change the the name to something else, it works perfectly!

I am using parsley.remote.min.js * Version 2.0.3 - built Mon Jul 21 2014 11:58:33

Sorry I cannot provide code right now, I just wanted to throw that out there. Is it possibly I am doing something wrong?


回答1:


When you name a form element "submit", you inadvertently override the form's submit method with an input object. For example, with this:

<form id="testForm">
    <input type="text" name="testInput" />
</form>

You can now access the input element by name through a property on the form object:

var testInput = document.getElementById('testForm').testInput;

Forms have a submit() method you can call programmatically (which is the same one invoked by clicking a button or input of "submit" type):

document.getElementById('testForm').submit();

Perhaps now you can see the problem by naming a form element "submit" -- you're taking away the form's ability to be submitted because submit() no longer exists -- it's been redefined as a property that returns a reference to your submit button.

More explanation is available here:

  • Why Form Elements should not be named submit?


来源:https://stackoverflow.com/questions/24996452/parsley-form-not-submitting-when-submit-button-has-name-submit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!