Custom javascript buttons in popup message box

Hi there,

How can I have say three buttons, save, dismiss and cancel in a javascript message box

I have the following which I would like to alter

Thanks

Max

<script LANGUAGE="JavaScript">
<!--
function confirmexitSubmit()
{
var agree=confirm("You are exiting this entry.\n\n Press OK to save changes!");
if (agree)
     company.submit();
else
     return false ;
}
// -->
</script>
LVL 1
MaximusMeridusAsked:
Who is Participating?
 
SnowFlakeConnect With a Mentor Commented:

<script LANGUAGE="vbscript">
sub confirmexitSubmit()
dim agree
agree=msgbox("You are exiting this entry." & vbCrLf & vbCrLf & "Press OK to save changes!", 3, "")

if (agree=vbYes) then
     company.submit()
elseif (agree=vbNo) then
     confirmexitSubmit=false
else ' (agree=vbCancel)
end if
end sub
</script>

not to forget points to sajuks for the idea of VBS.

You should be aware though that it increases the memory reuirements as it forces
the browser to load the vbscript engine and that it is also IE only as sajuks noted.

BTW, why do you need 3 options here ?
0
 
BatalfCommented:
You can't alter the standard confirm() dialog.

The alternative is a modal dialog box, but that's not compatible with all browsers.

var returnValue = window.showModalDialog('theUrl.html', null,'dialogHeight: 200px; dialogWidth: 440px; center: Yes; help: No; resizable: No; status: No;');

And then have put these 3 buttons in the file "theUrl.html". When any of them is clicked, you set the value of a variable called "returnValue" and thereafter closes the popupwindow.

example:

<input type="button" value="Cancel" style="width:75px" onclick="returnValue=1;self.close()">

This value("1") will be returned from the popup window and you could pick it up in the parent window, i.e.

var returnValue = window.showModalDialog('theUrl.html', null,'dialogHeight: 200px; dialogWidth: 440px; center: Yes; help: No; resizable: No; status: No;');
if(returnValue=='1'){ // Cancelled
    // Do something
}
if(returnValue=='2'){ //
    // Do something else.
}
0
 
sajuksConnect With a Mentor Commented:
the other alternative being designing for IE only ( using vbscript)
<html>
<head>
<title></title>
</head>
<body>
<SCRIPT LANGUAGE="VBScript">
sub button0_onclick
  msgbox "                 Do you want to continue?", 3, "VBScript Demo 0"
  end sub
//-->
</script>
<input type="button" name="button0" value="Submit">
</body>
</html>


0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
MaximusMeridusAuthor Commented:
can you have a javascript message box with Yes, No, Cancel ?
0
 
SnowFlakeCommented:
A third way would be do design your messegebox as a hidden DIV
which is part of your page and only show it when required,
this will allow you what ever customization you want (Icons/languages/buttons etc.)
but will require you to do some coding.
0
 
BatalfCommented:
>can you have a javascript message box with Yes, No, Cancel ?
No, you can't. You have to use an alternative like shown above: Modal Dialog box, VBScript message box or a customized div.
0
 
MaximusMeridusAuthor Commented:
Can someone kindly edit below to a VBScript message to include 3 buttons! That would be great!!! :)

<script LANGUAGE="JavaScript">
<!--
function confirmexitSubmit()
{
var agree=confirm("You are exiting this entry.\n\n Press OK to save changes!");
if (agree)
     company.submit();
else
     return false ;
}
// -->
</script>
0
 
MaximusMeridusAuthor Commented:
Excellent! Why on earth didn't anyone mention this!

Can a funtion prevent the page from exiting?

Thanks

Max
0
 
SnowFlakeCommented:
looking at it again it would not be reasonable to say "press OK" while there is no such button
so you might want to change the messege or choos some other set of buttons.

you can do that by replacing the 3 constant with any of the following constants:
VBOKOnly=0               -> OK
VBOKCancel=1            -> OK and cancel
VBAbortRetryIgnore=2 -> abort, retry, ignore
VBYesNoCancel=3       -> yes, no, cancel
VBYesNo=4                 -> yes, no  
VBRetryCancel=5         -> retry, cancel

In addition You might consider moving the first sentence to the title as in the following example:

e.g.
agree=msgbox("Press YES to save changes, No to discard your changes or cancel to continue editing ! ", vbYesNoCancel, "You are exiting this entry.")

0
 
SnowFlakeCommented:

> Excellent! Why on earth didn't anyone mention this!

please read above: It was mentioned by sajuks
and I also noted that on my post.

As for preventing a page from exiting the short answer is NO.
But for a appropriate answer you should explain better what do you mean
by "preventing a page from exiting":
 who initiated the exiting ?
 where does it exit too ?

In general I would suggest that you make this a new post
as it is a different Q.

SnowFlake.


0
 
MaximusMeridusAuthor Commented:
You're right.

Thanks Eyal

Max
0
 
SnowFlakeCommented:
Max,
It would be more appropriate to share the point with sajuks
that originally suggested the VBS approche.

Eyal.
0
 
MaximusMeridusAuthor Commented:
Ok

Moderator, please split points to:-

sajuks - 200
SnowFlake - 300

Thanks

Max
0
 
SnowFlakeCommented:
thanks max.
0
 
MaximusMeridusAuthor Commented:
No, Thank you

Max
0
 
MaximusMeridusAuthor Commented:
Thanks COBOLdinosaur!

I would like to know, how do you respond to these posts? Do you have a filter for "moderator" or is it done manually by checking every post?

Max
0
 
COBOLdinosaurCommented:
In this case SnowFlake let me know about it.

Anytime you need an editor, you can user our logon name @experts-exchange.com.  On the left side of the page is tha name of an editor for the topic, and most topic have more than one editor; we are not aloways on line.  

There is also the Community Support topic area for contacting moderators.  At the very top of the page on the right are three links "site news", "support", and "help".  The support link will take you to the Community Support topic where you can post a question or request and a modrtor or site admin will respond to it.

Those other two links are also useful.  The site news will give you a page wtih the lateste announcements, and the help link gives you links to all the FAQs and site documentation, which has been very well oranized, and grows with regular additions and updates of guidlines and information about how the site works.

BTW, I am also active as an expert in the topics where I edit, and I look at most threads; so I generally pickup things anyway, but not always in a timely manner.

COBOLdinosaur
Page Editor
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.