Link to home
Start Free TrialLog in
Avatar of MaximusMeridus
MaximusMeridus

asked on

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>
Avatar of Batalf
Batalf
Flag of United States of America image

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.
}
SOLUTION
Avatar of sajuks
sajuks

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MaximusMeridus
MaximusMeridus

ASKER

can you have a javascript message box with Yes, No, Cancel ?
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.
>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.
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>
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent! Why on earth didn't anyone mention this!

Can a funtion prevent the page from exiting?

Thanks

Max
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.")


> 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.


You're right.

Thanks Eyal

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

Eyal.
Ok

Moderator, please split points to:-

sajuks - 200
SnowFlake - 300

Thanks

Max
thanks max.
No, Thank you

Max
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
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