Double jQuery form trigger -


i having problem earlier jquery having submit() handler triggered twice. made test file basic submit event handler , worked fine yet following code not work:

$(document).ready(function(){     $('#regform').submit(function(e){         e.preventdefault();         $('#regform').fadeto('slow', 0, function(){             $('#regform').css('display', 'none');             $('#mainbox').animate({height: 90}, 100);             $('#one, #two, #three #four').fadeto('slow', 0, function(){                 $('#one').html('processing...').fadeto(300, 1, function(){                     $.post("/data/handles/account/register.php", {user: $('#user').val(), pass: $('#pass').val(), passc: $('#passc').val(), email: $('#email').val()}, function(data){                         if (data.error == 8) {                             alert('yes');                             /*                             $('#one').html('processing...' + data.content);                             $('#two').html('logging in...').fadeto('slow', 1, function(){                                 $('#three').html('redirecting...<a href="/account.php">[manual]</a>').fadeto('slow', 1, function(){                                     settimeout(redirect, 1000);                                 });                             });                             */                         } else {                             alert('no');                             /*                             $('#one').html(data.content);                             $('#two').html('<a href="#" reset>retry</a>').fadeto('slow', 1);                             */                         }                     }, "json");                 });             });         });     }); }); 

when test code alerts "yes" twice if enter correctly , makes 2 mysql entries in database php file. looked other questions relating problem none have fixed wondering if doing wrong here, or if theres way fix it. help.

the problem in line:

$('#one, #two, #three #four').fadeto('slow', 0, function(){ 

you attached fateto 3 elements, 4 if put "," after #three. so, after each fadeto jquery call callback function() post submit. can create count wait fadeto finish or change logic submit in "one" callback.

here sample:

var count = 0; // count of elements finished fadeto var limit = 2; // number of elements have wait fadeto $('#regform').submit(function (e) {     e.preventdefault();     $('#regform').fadeto('slow', 0, function () {         $('#regform').css('display', 'none');         $('#mainbox').animate({             height: 90         }, 100);         count = 0;         $('#one, #two, #three #four').fadeto('slow', 0, function () {             fadetosubmit();          });     }); });  function fadetosubmit(){     count++;     if(count == limit){             $('#one').html('processing...').fadeto(300, 1, function () {                 $.post("/data/handles/account/register.php", {                     user: $('#user').val(),                     pass: $('#pass').val(),                     passc: $('#passc').val(),                     email: $('#email').val()                 }, function (data) {                     if (data.error == 8) {                         alert('yes');                      } else {                         alert('no');                      }                 }, "json");             });     } } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -