[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Custom javascript buttons in popup message box

Posted on 2005-04-15
18
Medium Priority
?
2,086 Views
Last Modified: 2008-01-09
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>
0
Comment
Question by:MaximusMeridus
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13789975
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
 
LVL 33

Assisted Solution

by:sajuks
sajuks earned 800 total points
ID: 13790001
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
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13790202
can you have a javascript message box with Yes, No, Cancel ?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:SnowFlake
ID: 13790279
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
 
LVL 32

Expert Comment

by:Batalf
ID: 13790389
>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
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13790419
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
 
LVL 15

Accepted Solution

by:
SnowFlake earned 1200 total points
ID: 13791094

<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
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13791147
Excellent! Why on earth didn't anyone mention this!

Can a funtion prevent the page from exiting?

Thanks

Max
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13791242
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
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13791287

> 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
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13791320
You're right.

Thanks Eyal

Max
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13792061
Max,
It would be more appropriate to share the point with sajuks
that originally suggested the VBS approche.

Eyal.
0
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13792127
Ok

Moderator, please split points to:-

sajuks - 200
SnowFlake - 300

Thanks

Max
0
 
LVL 15

Expert Comment

by:SnowFlake
ID: 13792189
thanks max.
0
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13792463
No, Thank you

Max
0
 
LVL 1

Author Comment

by:MaximusMeridus
ID: 13796850
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
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 13796955
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question