0

In Javascript we can declare a variable and we can call a function. The function will return a value and will be assigned to the variable. Is this possible in jQuery?

I want to know if my previous function is finished or not. I want to get the result success or failure and call another function based on first function's result

I use a function setTimeout for blockUI.

How can I check if that timeout is due to another function?

Do .val or $.get work for the above purposes?

3
  • 12
    Please show your code as the question is quite incomprehensible. Commented Aug 19, 2010 at 17:49
  • 2
    jQuery is a JavaScript library, so it plays by the same rules. Commented Aug 19, 2010 at 17:50
  • Pardon, may be my English was weird. am using blockui function for fading the screen and show a messsage . this will be for 3000ms. so after 3000ms i want to call another fucntion which will redirect to a new page. So i want to know how can i call the second fucntion after 3000ms. Second question is ,like js var a =function dosome(); how to do in Jquery. 3rd is how can i redirect a page using jquery after 3000ms. I hope the questions are clear this time. Am a newbie and even asking questions having difficulties. Commented Aug 19, 2010 at 18:55

1 Answer 1

3

UPDATE: Based on your comments...

First question:

You should probably look at some of the blockUI demos.

It looks like blockUI has a callback onBlock: that calls a function after the fadeIn is done.

onBlock: function() { 
   alert('Page is now blocked; fadeIn complete'); 
}

Second question:

jQuery is just a library of javascript code, therefore you can assign functions to variables the same way you always do.

var a = function dosome() {
    // do something
};

a(); // call the function

Third question:

You mean you want to redirect after the 3000ms fadeIn of the blockUI? You would do it in the callback that I pointed out under question 1 above. But of course this will make the entire page change, including the blockUI.

window.location = "http://somedomain.com/some/path";

Some clarification in your question is needed.

It sounds like you have a function that sets a setTimeout() for some purpose, and that function is reused, so you need to reference the correct instance of setTimeout().

If so, you can have your function return the setTimeout() instance, and use that reference to clear it if needed.

function unblockUI(dur) {
    return setTimeout(function() {
        $.unblockUI();
    }, dur);
}

var someTimeout = unblockUI(1000);
clear(someTimeout);

var someOtherTimeout = unblockUI(1000);
clear(someOtherTimeout);

Is this close to what you're asking?

Sign up to request clarification or add additional context in comments.

2 Comments

hey..thnx anyway... how can i redirect to new page after 1000.?
thanks buddy. The callback worked actually i copy the blockui from the same demo site only. but i didnt look int the call back examples . setTimeout(function() { $.unblockUI({ onUnblock: function(){ window.location="google.com"; } }); }, 3000); work fine :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.