Bug Tracker

Opened 6 years ago

Closed 5 years ago

#6337 closed bug (fixed)

Button click within form causes submit event even though return false is there

Reported by: margieroginski Owned by: dmethvin
Priority: undecided Milestone: 1.4.3
Component: event Version: 1.4.2
Keywords: submit event return false Cc:
Blocked by: Blocking:


I have a small test case below where I create a button inside a form and set its onclick hander to my js function, show_input(), followed by a "return false", like this:

Immediately following that is a one line script that clicks the button.

	    <button id="testbutton1" onclick="show_input(); return false;">
	    <script type="text/javascript">

In jquery 1.3.2, when the .click() occurs, it calls show_input() and no submit event occurs aftwards, due to the return false. But in in Jquery 1.4.2, it calls show_input() and then the submit event fires (it does a GET), as if the return false is not there.

If I manually click the button, I do not see the submit event, so this seems to be somehow related to the click being inline.

Here is the exact html that can be used to replicate it.

    <script src="/site_media/js/jquery-1.3.2.js" type="text/javascript"></script>
    <script type="text/javascript">
      function show_input() {
        console.log("hello, world");

  <div id="container">
      <div class="taskform_row_description form-row">
	    <button id="testbutton1" onclick="show_input(); return false;">
	    <script type="text/javascript">

This seems to me to be a bug since it is very incompatible with previous behavior...

Thanks, Margie

Change History (4)

comment:1 Changed 5 years ago by dmethvin

  • Component changed from unfiled to event

comment:2 Changed 5 years ago by dmethvin

  • Owner set to dmethvin

It looks like the problem is in jQuery.event.trigger; the code to run inline scripts sets event.result to false but does not stopPropagation or preventDefault. I've taken the ticket and will put together a patch.

comment:4 Changed 5 years ago by john

  • Priority set to undecided
  • Resolution set to fixed
  • Status changed from new to closed

Fixed http://github.com/jquery/jquery/commit/adff8e45e255409e8f78a3347dea01bdbee0a53d

We only need to call preventDefault in this case.

Note: See TracTickets for help on using tickets.