DO11 Script - Determining which button was clicked

I am using GetString to prompt for some text but I also need to know which button the user clicks. GetString arguments are defined as so I was hoping that "n" in the following sample code would be populated with the index of the button that was clicked, however "n" remains undefined regardless of whether OK or Quit was clicked. Guidance from the experts would be appreciated.

[code]@language jscript

function OnClick(ClickData)
{
var n
var s = ClickData.Func.Dlg.GetString("Enter a workspace name..","",-1,"OK|Quit","WorkSpace Prompt Dialog",0,n)
DOpus.OutputString("User entered.. " + s);
DOpus.OutputString("n = " + n);
}[/code]
Output from a test run..

User entered.. blah blah n - undefined
By trial and error I managed to establish that using -1 for allows any length of string to be entered. My guesses of "0" for and a defined variable "n" for are precisely that... guesses. Once again, expert guidance would be appreciated.

Regards, AB

JScript doesn't support pass-by-reference (one of the few advantages VBScript has over it), however you can do this by building up the dialog using the object's properties and calling the Show method which returns the selection value:

[code]@language jscript

function OnClick(ClickData)
{
var n
var dlg = ClickData.Func.Dlg;

dlg.message = "Enter a workspace name..";
dlg.buttons = "OK|Quit";
dlg.title = "WorkSpace Prompt Dialog";
dlg.max = 255;
n = dlg.Show();

DOpus.OutputString("User entered.. " + dlg.input);
DOpus.OutputString("n = " + n);
}[/code]

Thanks Jon

I had actually tried what you suggested but omitted the dlg.max setting so the dlg.show failed. All good now.

Regards, AB

Can I have VBScript example for this please?
And how select text in field by default?

Simple VBScript example:

(I've changed the max length argument from -1 to 1024 as I'm not sure what -1 does there.)

[code]option explicit

Function OnClick(ByRef ClickData)

Dim n
Dim s

s = ClickData.Func.Dlg.GetString("Enter a string...","Default String",1024,"OK|Quit","String Prompt",0,n)
DOpus.Output "User entered: n = " & n & ", s = " & s

End Function[/code]

If you want to select the default string, the one-line GetString helper function doesn't cut it anymore and you need to use the full object (from Jon's example), which has more options:

[code]option explicit

Function OnClick(ByRef ClickData)

Dim n
Dim s
Dim dlg

Set dlg = ClickData.Func.Dlg

dlg.message = "Enter a string..."
dlg.default = "Default String"
dlg.select = true ' <-- This is what selects the default input.
dlg.max = 1024
dlg.buttons = "OK|Quit"
dlg.title = "String Prompt"

n = dlg.show
s = dlg.input

DOpus.Output "User entered: n = " & n & ", s = " & s

End Function[/code]