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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:37:15+00:00 2026-05-25T09:37:15+00:00

I am currently writing a custom dialog box script in JavaScript (to show dialog

  • 0

I am currently writing a custom dialog box script in JavaScript (to show dialog boxes with a choice of buttons, titles, etc.) thus mimicking C#’s MessageBox.Show() method. However, I’m having problems with correctly returning values from the function.

For example, the Show() method I have created is static, and called as follows from a button click:

<input type="button" onclick="return MessageBox.Show(dialogueMessage, 'Really Delete?', 'confirm', false)") />

Once the MethodBox.Show() function has been called, the dialog is displayed. I would like the option so that when a user clicks on the “Yes” button, the MessageBox.Show() function returns true, otherwise it returns false. The code I have for creating the (dynamic) buttons is as follows:

var yesButton = document.createElement('input');
yesButton.setAttribute('type', 'button');
yesButton.setAttribute('value', 'Yes');
yesButton.setAttribute('name', 'button-yes');
yesButton.onclick = function() { MessageBox.Hide(); return true; }; 

var noButton = document.createElement('input');
noButton.setAttribute('type', 'button');
noButton.setAttribute('value', 'No');
noButton.setAttribute('name', 'button-no');
noButton.onclick = function() { MessageBox.Hide(); return false; };

However, as you can appreciate, the ‘return false’ / ‘return true’ statements refer to the button itself, and not the function (MessageBox.Show()). What I would like to know, is if there’s a method I can use return the function when (and only when) the user clicks one of the buttons, so that the button clicked to call the function can be correctly used.

It’s difficult for me to explain what I’m trying to achieve, but the above should make sense.

Thanks,
Ben.

  • 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-25T09:37:16+00:00Added an answer on May 25, 2026 at 9:37 am

    The way you are doing this wont let you return any value, because the function has finished just after the dialog box has been created.
    I assume you want to cancel the default action of a button when pressed… So do the following.

    If the button, in Javascript is in var theButton.

    theButton.addEventListener('click',
        function(e)
        {
            e.preventDefault(); // So clicking will not fire any submit
                                // if the button was inside a form element.
    
            MessageBox.Show(dialogueMessage, 'Really Delete?', 'confirm', false, this);
            // Here I send a button reference to be able to fire the event ______↑
            // you must add an extra parameter to hold it then...
        } 1);
    

    Then inside the MessageBox.Show() method, you do as follows, assuming that the this keyword was passed as, buttonRef.-

    var yesButton = document.createElement('input');
    yesButton.setAttribute('type', 'button');
    yesButton.setAttribute('value', 'Yes');
    yesButton.setAttribute('name', 'button-yes');
    yesButton.onclick = function() { MessageBox.Hide(); butonRef.click(); }; 
    
    var noButton = document.createElement('input');
    noButton.setAttribute('type', 'button');
    noButton.setAttribute('value', 'No');
    noButton.setAttribute('name', 'button-no');
    noButton.onclick = function() { MessageBox.Hide(); };
    

    Then, if yes was pressed, the input element will fire a submit event just like if it was pressed.

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

Sidebar

Related Questions

I'm writing a custom form UI and currently building a select box replacement. The
I am currently writing a small custom memory Allocator in C++, and want to
I'm currently writing a simple .sh script to parse an Exim log file for
I'm currently writing DataTemplate for my custom type lets say FootballPlayer. In this template
I'm currently writing a program in c# wpf with a custom window. So because
I am writing a custom tool and I currently have it doing what I
I'm currently writing a custom-designed tab control. I created my own control instead of
I am currently writing a few custom template tags but for some reason they
I'm currently writing a quick custom encoding method where I take a stamp a
I'm currently writing an custom control which has to hold child control and have

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.