Click to See Complete Forum and Search --> : confirm box


luizaha
04-30-2003, 03:03 PM
Hi,
I'm using Javascript confirm boxes which give me two options: OK and Cancel, is it possible to change it to Yes and No?
Thanks, Luiza

Shampie
04-30-2003, 03:07 PM
if there is that be new to me too..
but why would you use it instead of OK/Cancel?

to agree press OK if not press Cancel..

luizaha
05-01-2003, 06:40 AM
The reason I want to change options to Yes and No is because I let the user cancel notifications from the web page, so Ok and Cancel are confusing in this case. Is there any javascript functions I can use?
Thanks, Luiza

requestcode
05-01-2003, 07:26 AM
You can't change those so you will have to create a custom confirm box using a combination of JavaScript and DHTML. Here is an example of one I created for someone else:
<html>
<head>
<title>Custom ConFirm, Alert and Prompt</title>
<style>
/* You can modify these styles to anything you want (or is allowed). */
/* These are used by both browsers. You can set these to your preferences. */
.td1style {font-weight:bold;border:1px solid black;background-color:lightgrey;color:blue;font-size:14px;fontFamily:Verdana;}
.td2style {font-weight:bold;border:1px solid black;background-color:lightyellow;font-size:12px;font-family:Verdana;}
/* the style below is for the links that are inside the div when it pops up */
.linkstyle {font-weight:bold;font-size:12px;text-decoration:none}
</style>
<script language="JavaScript">
var msgtop=50 // Set the top position of the div
var msgleft=20 // Set the left position of the div

/* The following three variables are for setting the properties of your table contained within the div. */
var tborder="0"
var cspace="0"
var cpad="0"
var tabheight=50 // Set the height of table
var tabwidth=150 // Set the width of table
var td1height=10
var td2height=30
var boxt=""
function Domsg(flag)
{
hidebox() // Hide the box after clicking on text link in box
if(flag=="Yes")
{
msg="You Clicked "+flag+"!"
}
else
{msg="Why did you click "+flag+"?"}
document.formbx.result.value=msg
}
function DoFormbox(msgtext)
{
theString="<table width='"+tabwidth+"' height='"+tabheight+"' border="+tborder+" cellspacing="+cspace+" cellpadding="+cpad+"><tr><td height='"+td1height+"' class='td1style' align='left'><b>"
theString+=""+msgtext+"</b></td></tr><tr><td height='"+td2height+"' align='center' class='td2style'><a href='javascript:Domsg(\"Yes\")' class='linkstyle'>Yes</a>&nbsp &nbsp<a href='javascript:Domsg(\"No\")' class='linkstyle'>No</a></td></tr></table>"
if (document.layers) // Netscape 4.0+
{
document.formbox.document.write(theString)
document.formbox.document.close()
document.formbox.left=msgleft
document.formbox.top=msgtop+40
document.formbox.visibility="show"
}
else
{
if(document.getElementById) // Internet Explorer 5.0+ and Netscape 6.0+
{
elm=document.getElementById("formbox")
elm.innerHTML=theString
elm.style.top=msgtop
elm.style.left=msgleft
elm.style.visibility = "visible"
}
}
}

// This function is for hiding the div
function hidebox()
{
if (document.layers) // Netscape 4.0+
{
document.formbox.visibility="hidden"
}
if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
{
elm.style.visibility="hidden"
}
}
</script>
</head>
<body>
<div id="formbox" style="position:absolute;visibility:hidden;left:0;top:0;"></div>
<center>
<h1>Custom Confirm</h1>
<form name="formbx">
<input type="text" name="result" size="30">
</form>
<a href="javascript:DoFormbox('Are you sure?')">Click Me for a Confirm Box</a><br>
</center>
</body>
</html>