Click to See Complete Forum and Search --> : Yes and No buttons instead of OK and Cancel using javascript:confirm


amitbidkar
03-11-2004, 05:41 AM
Hi All,

I am just a beginner for javascript.
I do not know how to get yes and No buttons instead of OK and Cancel using javascript:confirm. Also if you could guide me with this.

On clicking Yes or No it should load a different url.

Pittimann
03-11-2004, 07:33 AM
Hi!

Actually, you cannot change the confirm and its' "collegues" prompt and alert. You could use VBScript to do what you like, but it would only work in IE.

Example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
IE4 = document.all;
function newConfirm(title,mess,icon,defbut,mods) {
if (IE4) {
icon = (icon==0) ? 0 : 2;
defbut = (defbut==0) ? 0 : 1;
retVal = makeMsgBox(title,mess,icon,4,defbut,mods);
retVal = (retVal==6);
}
else {
retVal = confirm(mess);
}
return retVal;
}
//-->
</script>
<SCRIPT LANGUAGE="VBScript">
<!--
Function makeMsgBox(title,mess,icon,buts,defbut,mods)
butVal = buts + (icon*16) + (defbut*256) + (mods*4096)
makeMsgBox = MsgBox(mess,butVal,title)
End Function
-->
</SCRIPT>
<script language="JavaScript" type="text/javascript">
function showConfirm() {
myBooleanVariable = newConfirm(
'My Confirm Title',
'My Confirm Message',
2,0,0)
if (retVal==true) return true;
else{
location.href='blah2.htm';
return false;
}
}
//-->
</script>
</head>
<body>
<a href="blah.htm" onClick="return showConfirm()">click</a>
</body>
</html>

This example would show "yes" and "no" buttons in IE and a normal confirm in other browsers.

If you want to play around with such stuff - here is a link to a code generator for that and even more stuff (like IE Box with more than two buttons etc.):

http://www.webreference.com/dhtml/dynomat/dialogs/main.html

Cheers - Pit

gil davis
03-11-2004, 07:36 AM
There are no options to customize the confirm box. Sorry.

moreta
07-28-2004, 03:30 PM
I found several threads that create message boxes with a recurring suggestion of combining JS with VBScript for IE4+ browsers. Does VBScript have to be enabled in IE4+ (like JS), or is it always on?

Thanks!
Moreta