Drupal Form Button + "Are you sure"-Button I am trying to add an own JS function to a Drupal Core Form - think Config, Development, Clean Cache. This function basically just asks if the user is sure. Here is what I have so far:

Drupal.behaviors.confirm_delete = {

    attach: function (context, settings) {

         jQuery("#field-module-subsections-values input[id$='-remove-button']", context).bind('mousedown', function (ev) {

            ev.stopImmediatePropagation();
            ev.preventDefault();

            var followLink = window.confirm(question);

            if (followLink) {
                jQuery(this).click();
            }

            return false;

        });
    }
}


The problem I have is, that the function gets called before the click-event (thanks to mousedown), but the Ajax action on the button still fires. Maybe someone has a hint as to why?
Using hook_form_alter you can implement simple popups like this using #attributes.

 $form['submit']['#attributes'] =&gt; array(
  'onclick' =&gt; 'if(!confirm("Are you sure?")){return false;}',
 );


or

$form['submit']['#attributes']['onclick'] = 'if(!confirm("Are you sure?")){return false;}';