locked
How to display a dialog selection window using JScript? RRS feed

  • Question

  •  

    Hi.

     

    I Would like to display a window which allows to user make some choices, for example: "Do you want to continue?" with two buttons, "Yes","No".

     

    How to do this?

     

    Thanks for your replies.

    Wednesday, February 6, 2008 1:02 PM

Answers

  •  

    Take a look at this:-

     

    Code Snippet

    var prompts = {}
    prompts.OKOnly =           0  
    prompts.OKCancel =     1  
    prompts.AbortRetryIgnore = 2  
    prompts.YesNoCancel =     3  
    prompts.YesNo =       4  
    prompts.RetryCancel =    5  
    prompts.Critical =     16 
    prompts.Question =     32 
    prompts.Exclamation =    48 
    prompts.Information =    64 
    prompts.DefaultButton1 =   0  
    prompts.DefaultButton2 =   256 
    prompts.DefaultButton3 =  512 
    prompts.OK =     1
    prompts.Cancel = 2
    prompts.Abort =  3
    prompts.Retry =  4
    prompts.Ignore = 5
    prompts.Yes =    6
    prompts.No =   7

    var sh = new ActiveXObject("WScript.Shell");

    var retVal = sh.Popup("Do you want to continue?", -1, "My Title", prompts.YesNo + prompts.Question)

    if (retVal == prompts.Yes)
     WScript.echo("You said yes")
    else
     WScript.echo("You said no")

     

     

     

    This achieves what you want.  Note you can get all sorts of variations by adding button requirements and icon requirements together.  Also an undocumented feature is that you can specify which of the up to 3 buttons displayed is the default button.

     

    Thursday, March 13, 2008 11:59 AM

All replies

  •  

    Did you try confirm function of javascript?

     

    Sample:

    Code Snippet

    <html>

    <body>

     

    <script type="text/javascript" language="javascript">

    function test()

    {

    confirm("Do you want to continue?");

    }

    </script>

     

    <input type="button" onclick='test()' value="Ok" />

    </body>

    </html>

     

     

    Monday, February 11, 2008 4:33 AM
  •  

    Thanks, but how am I to call this from my .js file? Smile Iam interested in JScript, not javascript.
    Monday, February 11, 2008 8:00 AM
  •  

    Take a look at this:-

     

    Code Snippet

    var prompts = {}
    prompts.OKOnly =           0  
    prompts.OKCancel =     1  
    prompts.AbortRetryIgnore = 2  
    prompts.YesNoCancel =     3  
    prompts.YesNo =       4  
    prompts.RetryCancel =    5  
    prompts.Critical =     16 
    prompts.Question =     32 
    prompts.Exclamation =    48 
    prompts.Information =    64 
    prompts.DefaultButton1 =   0  
    prompts.DefaultButton2 =   256 
    prompts.DefaultButton3 =  512 
    prompts.OK =     1
    prompts.Cancel = 2
    prompts.Abort =  3
    prompts.Retry =  4
    prompts.Ignore = 5
    prompts.Yes =    6
    prompts.No =   7

    var sh = new ActiveXObject("WScript.Shell");

    var retVal = sh.Popup("Do you want to continue?", -1, "My Title", prompts.YesNo + prompts.Question)

    if (retVal == prompts.Yes)
     WScript.echo("You said yes")
    else
     WScript.echo("You said no")

     

     

     

    This achieves what you want.  Note you can get all sorts of variations by adding button requirements and icon requirements together.  Also an undocumented feature is that you can specify which of the up to 3 buttons displayed is the default button.

     

    Thursday, March 13, 2008 11:59 AM
  •  Heavenwood wrote:

     

    Thanks, but how am I to call this from my .js file? Iam interested in JScript, not javascript.

     

    I think you're a little confused by the distinction between JScript and Javascript.  Javascript is a more general term used to refer to all implementations of the language and is more tightly related to the Mozilla implementation of the language.

     

    JScript is used only to refer to Microsoft implementation of the Javascript (or ECMAScript) language.

     

    Neither refer to the context in which they are executed.  However all implementations do require a context.  The most common context is in a browser and is tied very tightly to the presence of DHTML DOM.  Hence its common to assume its presence.  However things like alert and confirm are provided by the context not the language.

     

    I assume in my other reply that the context that you are concerned with is wscript.

     

    Thursday, March 13, 2008 12:04 PM
  •  

    Thanks for excellent example and clearing the confusion Wink

     

    Yes, my question was about wscript context. Smile

     

     

    Thursday, March 20, 2008 12:05 PM
  • jPaq is a new customizable JScript library which provides this functionality.  The documentation can be found here:  http://jpaq.org/documentation/alert%28%29/1.0.  The build that only includes this alert function can be found here:  http://jpaq.org/download/1.0.0.000001.  If you have any suggestions for what else can be added to this JavaScript/JScript library, please let me know.
    Tuesday, February 15, 2011 5:07 PM