最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery .Submit() is not triggering submit event - Stack Overflow

programmeradmin4浏览0评论

I have a very small problem,

I want to submit my code using jQuery on dropdown change:

 $("#mydropDown").change(function(){           
        $("#myForm").submit();
    });

but it is not submitting.

I also fired following code in Firebug console:

$("#myForm").submit();

it given me this output

[form#myForm]

I'm not getting what is the problem... :o?

I have a very small problem,

I want to submit my code using jQuery on dropdown change:

 $("#mydropDown").change(function(){           
        $("#myForm").submit();
    });

but it is not submitting.

I also fired following code in Firebug console:

$("#myForm").submit();

it given me this output

[form#myForm]

I'm not getting what is the problem... :o?

Share Improve this question edited Feb 26, 2021 at 18:39 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jul 25, 2012 at 5:28 Ravikumar SharmaRavikumar Sharma 3,7405 gold badges38 silver badges61 bronze badges 5
  • 1 try $("#myForm")[0].submit(); – jay c. Commented Jul 25, 2012 at 5:31
  • <form enctype="multipart/form-data" id="myForm" method="post" action="mypage"> <select id="myDropDown" >Options</select> </form> – Ravikumar Sharma Commented Jul 25, 2012 at 5:32
  • Do you have any submit event bound to this form? event handlers may prevent default submit actions if it returns false or invokes preventDefault method on event object. try to see jQuery bound event handler via $._data($('#myForm')[0]).events.submit – otakustay Commented Jul 25, 2012 at 5:32
  • @jay > $("#myForm")[0].submit(); returns undefined method in console – Ravikumar Sharma Commented Jul 25, 2012 at 5:34
  • Isn't mydropDown typo of myDropDown? – Mics Commented Jul 25, 2012 at 5:34
Add a ment  | 

4 Answers 4

Reset to default 3

hi that time I used unbind but I really wanted to find to why it is happening. later I found answer of this question. I'm not much sure it is correct or not but it worked for me. In the same form ('#myForm') there is a submit button with id='submit' and name='submit'. I changed both to submit_btn and it worked for me hope it may help...

Thank you for your support!!!

You may have another event bound to your form that is cancelling the submit event.

To check this, you could execute the following in the console:

console.log($('#myForm').data('events'));

Which will output all events bound to your form.

May be, you have another event bound, if want cleaning up:

 $("#mydropDown").change(function(){           
        $("#myForm").unbind().submit();
    });

make sure that is within

$(document).ready(function(){
  //....
})

The jquery is pretty basic so it must be something else. To debug this I would just ment out all the jquery and see if you can get the form to submit with just a submit button.

If that doesnt work it would look at your action page.

发布评论

评论列表(0)

  1. 暂无评论