Cannot submit form with .submit()

后端 未结 2 1266
野的像风
野的像风 2020-12-12 00:11

I need to trigger a form submit event when any form value changes and all the fields in the form are filled. Everything in this works apart from the $(\'#date_filter_f

2条回答
  •  天涯浪人
    2020-12-12 00:36

    Your submit button is named 'submit', and it clashes with the form.submit method.

    This happens because browsers provide shortcut accessors to form elements, properties that refer to the elements, are bound to the form element, using the name attribute as the property name.

    An element named submit will replace the form.submit method, you should simply change name.

    Also keep in mind that in IE you will have the same problems with the id attribute.

    See also:

    • Form Access - The Most Common Mistake

    The most common mistake made when defining the form HTML that a script will interact with follows from the existence of the shortcut accessors for form controls. It is to give the control a NAME (or possibly ID) that corresponds with an existing property of FORM elements. And the most common example of that is an INPUT element of type="submit" with the NAME "submit". Because the named controls are made available as named properties of the FORM element this INPUT element is made available under the property name "submit". Unfortunately FORM elements already have a property with the name "submit", it is the submit method that can be used to submit the form with a script.

提交回复
热议问题