David David - 7 months ago 7
PHP Question

Input name submit not submit the form

If I name button to "submit" the form is not submitting. But If I changed the name something else the form is submitting.

HTML CODE:

<form name="my_form" action="/search" method="get" id="my_form">
/** code **/
<button name="submit" type="submit"><i class="fa fa-angle-right"></i></button>
</form>


Here If I change
button
name somthing else then it will work and submit the form.

JQUERY CODE

$( document ).ready(function() {
$('.attr_list').on('ifChanged', function(event){
alert("message will display"); // here alert will come but form is not submitting
$("#my_form").submit();
});
});


Why it is not submitting if I named the button to "submit" ?

Answer

I think you should change your button name from "submit" to anything else.

Reason:

Form elements have a property called submit which is the function you can call to submit them. (jQuery uses this under the covers when you call submit on the jQuery instance.) But Form elements also receive properties for each of the fields in the form, using the field's name, and so if you have a field called "submit", it overrides the submit function, which means you can't submit the form programmatically.

Your code should be:

<form name="my_form" action="/search" method="get" id="my_form">
/** code **/
<button name="othername" type="submit"><i class="fa fa-angle-right"></i></button>
</form>

It will work....