tags:

views:

118

answers:

2

Hi folks,

I'm trying to use jQuery's queue() to show() a div prior to submitting a form. However my current code just immediately submits the form before the show() effect even starts. BTW #savebutton is not a submit element, just an image with this click event.

$("#savebutton").click(function () {
    $("#saving").queue(function()
    {
        $("#saving").show("slow");
        $("#form1").submit();
    });
});

How can I make sure the show() completes before submitting?

Thanks for any advice!!

JG

A: 

LOL, had the queue assigned to the wrong id. Corrected code works:

$("#savebutton").click(function () {
    $("#savebutton").queue(function()
    {
        $("#saving").show("slow");
        $("#form1").submit();
    });
});
jerrygarciuh
`submit` doesn't queue, it will execute straight away with the animation going on in the background.
bobince
+3  A: 

You could use show(speed, callback) function:

$('#savebutton').click(function () {
    $('#saving').show('slow', function() {
        $('#form1').submit();
    });
});
Darin Dimitrov
That works better than my answer! Thank you!
jerrygarciuh