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 6087395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:51:56+00:00 2026-05-23T11:51:56+00:00

I would like to pass the function some javascript to be executed when the

  • 0

I would like to pass the function some javascript to be executed when the user presses one of the buttons, but currently when I press the “No” or “Yes” buttons on the dialog box nothing happens, it just sits there…no error shows in firebug. If I hard code “alert(‘hi’)” into the dialog button it works fine, so there must be something in passing the javascript as part of the function parameters.

How can I get this to work? Thanks in advance.

Heres my javascript function:

function confirm_yes_no(xtitle,msg, btn_yes_txt, btn_no_txt, btn_yes_js, btn_no_js)
{
    var button_yes = btn_yes_txt;
    var button_no = btn_no_txt;
    var dialog_buttons = {};

    dialog_buttons[button_yes] = function(){ btn_yes_js }
    dialog_buttons[button_no] = function(){ btn_no_js }

    $("#modal_confirm_yes_no").html(msg);
    $("#modal_confirm_yes_no").dialog({
                title: xtitle,
                bgiframe: true,
                autoOpen: false,
                height: 150,
                width: 300,
                modal: true,
                buttons: dialog_buttons
            });

    $("#modal_confirm_yes_no").dialog("open");
}

Here’s how I call the function:

confirm_yes_no("Print Checks", "Would you like to print checks now?", "Yes", "No", "alert('you clicked yes');", "alert('you clicked no');");
  • 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-05-23T11:51:57+00:00Added an answer on May 23, 2026 at 11:51 am

    If btn_yes_js is a reference to a Javascript function just do:

    dialog_buttons[button_yes] = btn_yes_js;
    

    and likewise for btn_no_js.

    If instead what you’re saying is that btn_yes_js is a string containing the source of a JS function, and it appears that you are – DON’T DO THAT!!

    Your call should look like:

    confirm_yes_no("Print Checks", "Would you like to print checks now?", "Yes", "No",
        function() {
           alert('you clicked yes');
        },
        function() {
           alert('you clicked no');
        }
    );
    

    i.e. pass in references to functions (anonymous functions in this example), not strings that would have to be passed to the nasty, horrible, never-ever-use-on-pain-of-death eval() function.

    See http://jsfiddle.net/alnitak/WHeRF/

    I’d also note that your code ultimately will need more work, since whilst you’re registering callback handlers, neither of them actually close down or destroy the dialog box.

    You’ll actually need something more like:

    dialog_buttons[button_yes] = function() {
        $('#modal_confirm_yes_no').dialog('close').dialog('destroy');
        btn_yes_js.call(ctx);
    }
    

    i.e. a local function which closes the dialog box cleanly, and then invokes the relevant callback function. You may wish to add your own ctx variable which will become the value of this within your callbacks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create some sort of function where you pass in a
I have this function that works, but I would like to make this one
I would like to pass to a jQuery function a regular function, instead of
I need to pass multiple arguments to a function that I would like to
I would like to pass a function as a template argument to another function
I would like to have a function that modifies some variable list of parameters
I would like to add some variables when my window.open function fires. Example: <a
I would like to put some logging statements within test function to examine some
I would like to move all Javascript from HTML markup into separate files but
I would like to pass an argument(s) to a method being defined using define_method,

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.