rookie question on "confirm" dialog

C

calan

I need a dialog box with Yes, No, and Cancel buttons that pops up when a
link is clicked.

I'm using asp on the server side, and basically, if the user clicks yes, I
want to go to a certain page and pass a certain variable value. For example:

href="my_page.asp?answer=yes"

If they click no, I would call :

href="my_page.asp?answer=no"

If they select cancel, I return false to cancel the default link action and
nothing happens.

What is the easiest and cleanest way to accomplish this?

TIA!

Calan
 
D

Daniel Kirsch

calan said:
I need a dialog box with Yes, No, and Cancel buttons that pops up when a
link is clicked.

I'm using asp on the server side, and basically, if the user clicks yes, I
want to go to a certain page and pass a certain variable value. For example:

href="my_page.asp?answer=yes"

If they click no, I would call :

href="my_page.asp?answer=no"

If they select cancel, I return false to cancel the default link action and
nothing happens.

What is the easiest and cleanest way to accomplish this?

As you cannot change the default dialogs and in time of popupblockers
and no real modal dialogs in gecko based browsers, I use my own <div>
based dialog with the elements I need. I therefore created a method
which will show up to three buttons with each caption passed to the
dialog. Something like:

function MsgBox(title,text,btn1,btn2,btn3) {
this.title = title;
this.text = text;
this.btn1 = btn1;
this.btn2 = btn2;
this.btn3 = btn3;

if (!btn1)
btn1 = "OK";

// some more code to fill the dialog and show the div.
}

Your HTML might look like this (with some additional CSS)

<div id="msgBox">
<div id="msgBoxTitle"></div>
<div id="msgBoxText"></div>

<div id="msgBoxBtnContainer">
<div id="msgBoxBtn1" onclick="MsgBox.notify(1)"></div>
<div id="msgBoxBtn2" onclick="MsgBox.notify(2)"></div>
<div id="msgBoxBtn3" onclick="MsgBox.notify(3)"></div>
</div>
</div>

When the user presses one of the buttons, another method gets called
(MsgBox.notify) which stores some properties like the button pressed,
it's caption etc. That method will call another predefined method that
was defined as recall function before calling the dialog:

MsgBox.notify = function(btnID) {
// code to hide the div dialog and set some props

this.returnValue = btnID;
this.returnString = this["btn" + btnID];
if (typeof this.returnMethod == "function")
this.returnMethod(this);
this.returnMethod = null;
}

Call it like this:

function foo() {
MsgBox.returnMethod = userAnswer;
MsgBox("Logout","Do you want to save your
settings?","Yes","No","Cancel");
}

function userAnswer(msg) {
if (msg.returnString == "Yes")
// do something on yes
else if (msg.returnString == "No")
// do something on no
else
// cancel
}

HTH
Daniel
 
C

calan

The link is to an order number in a database; clicking the link allows them
to edit the order. What I'm trying to do is, when the link is clicked, they
have the option of editing the existing order, or bumping it a revision
number and then editing.

"Do you wish to edit the existing order?"
yes = go to edit page; pass a variable that tells my asp to not do
anything special

no = go to edit page; pass avariable that tells asp to copy all order
data to new records and make it current, then edit that.

cancel = do nothing; stay on the list of orders page.
 
M

Martin Bialasinski

calan said:
"Do you wish to edit the existing order?"
yes = go to edit page; pass a variable that tells my asp to not do
anything special

no = go to edit page; pass avariable that tells asp to copy all order
data to new records and make it current, then edit that.

cancel = do nothing; stay on the list of orders page.

The meaning of "no" does not match the question. Make it two links,
"edit" and "copy".

Bye,
Martin

PS: Please don't top quote.
 
R

RobG

Martin said:
The meaning of "no" does not match the question. Make it two links,
"edit" and "copy".

What, and save the user a click? Good grief, what are buttons for if
not for clickin'!! ;-)
 
C

calan

Well thanks for the helpful input into my original question... If I could
use two links I would :)
 
M

Martin Bialasinski

calan said:
Well thanks for the helpful input into my original question... If I
could use two links I would :)

The are no dialog boxes with three options in javascript.

If you want it cross-browser, a simulated dialog box with a high
z-index div will work, as already suggested.
To make it modal, maybe a transparent backpane with onclick captured
and cancled could be used. Don't know if this works.

Or you can make it old-style:
Intermediate page with "Edit this order", "Copy order" and
"Back" links.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top