Form does not submit because of command $ ("# div"). attr ("disabled", true); of jquery. What to do to solve?

1
$("#button").click(function(){
    $("#button").attr("disabled",true);
    $("#button").animate({opacity:0.2});

    var nome    = $("#nome").val();
    var telefone    = $("#tel").val();
    var email   = $("#email").val();
    var onde    = $("#onde").val();
    ......         
)};

In IE and Firefox works fine, when I click the button it sends the data via jquery to a page and has to disable the button but does not send the data when it is through google chrome.

    
asked by anonymous 26.05.2014 / 17:25

2 answers

1

Put a setTimeout of 1 millisecond in the button lock action:

$('button').on('click',function(){
    var btn = $(this);
    setTimeout(function(){
        btn.attr('disabled',true);  
    },1);
   //...
});

In this way it does not stop sending form but still locks up fast enough to avoid further user clicks.

Exemplo

    
26.05.2014 / 18:45
0

Why do not you use the form onsubmit event to perform the lock?

$("#form").submit(...);
// Ou
$("#form").on('submit', (function(){
    $("#button").attr("disabled",true);
    $("#button").animate({opacity:0.2});

    var nome    = $("#nome").val();
    var telefone    = $("#tel").val();
    var email   = $("#email").val();
    var onde    = $("#onde").val();
    ......
)};

I believe this behavior is correct, but it is not consistent for all browsers ...

Of course, if you disable the button that submits the form it will not submit. I believe that using the onsubmit event is more certain because it occurs during submit and does not run the risk of blocking submit .

Take a look at the jQuery documentation for the submit event.

    
26.05.2014 / 17:47