Skip to content
Advertisement

Submit a form with mouse middleclick button

I’m working on a system and I want to make the system easier to use. I have few forms on a page and huge tables in each. I’m not good at JS so any advice would be appreciated.

Answer

Use a click event listener:

document.body.addEventListener('click', function(e){
    if (e.button == 1){
       document.formname.submit();
    }
});

EDIT:

As per the new jQuery tag, it’s slightly faster:

$('body').click(function(e){
   if((!$.browser.msie && e.button == 1) || ($.browser.msie && e.button == 4)){ 
     // IE exception thanks to @Elias Van Ootegem
     $('form.myForm').submit();
   }
});
Advertisement