Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7918049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:22:29+00:00 2026-06-03T15:22:29+00:00

Is it possible to have the return of a JS function depend on user

  • 0

Is it possible to have the return of a JS function depend on user action?

So let’s say I have function a and function b.

Function b brings up a dialog with two buttons, one which returns true and one which returns false. Can I call b from a and force a to wait for the return from b before continuing it’s operation?

Example code:

function a(){
    if(b()){
        do x
    }else{
        do y
    }
}

function b(){
$("#anElement").dialog({
    title: "This is a Dialog",
    buttons:{
        "Yes": function(){
            //do some stuff
            $(this).dialog("close");
            return true;
        },
        Cancel: function(){
            //do some stuff
            $(this).dialog("close");
            return false;
        }
    }
});
}

I guess this is a lot like a confirm, but I want to build more than just yes / no on top of it. Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:22:31+00:00Added an answer on June 3, 2026 at 3:22 pm

    No, you can’t halt a function’s execution (well, you could with an infinite while loop with a break condition, but that’s terrible practice). However, you could split A into two functions and call the other half of function A from function B. You could even pass in a return function to function B and call that, passing in the value of the user action.

    Example:

    function A() {
        // do stuff
        B(finishA);
    }
    
    function B(callback) {
        if(someCondition) {
            callback(true);
        } else {
            callback(false);
        }
    }
    
    function finishA(userInput) {
        if(userInput) {
            // do something if the user clicked okay
        } else {
            // do something if the user clicked cancel
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to define a member function which have the return type same
Possible Duplicate: c++ virtual function return type I have a simple but confusing question
Is it possible to have a function with two returns like this: function test($testvar)
Possible Duplicate: Why is this function returning “undefined”? Let's assume I have the following
Is it possible to have a function return multiple types as long as they
Is it possible to have the router return an error code (or an entire
Is it possible to have a method return different values depending on context (how
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: How to make return key on iphone make keyboard disappear? I have
I have the following query which returns a list of questions and the possible

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.