...

View Full Version : confirm() yes/no



dallen24
07-24-2002, 05:48 AM
Hi. Does anyone have a JavaScript function that simulates confirm(), but uses [Yes][No] buttons?

requestcode
07-24-2002, 02:48 PM
Here is one that I put together 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>

Tuno
10-05-2007, 11:08 AM
This doesn't simulate the pop like confirm. Is there a way to do this like confirm only with 'Yes' and 'No' buttons?

Philip M
10-05-2007, 12:15 PM
If your question is "Is it possible to alter the 'OK' and 'Cancel' buttons in a Javascript confirm box to 'Yes' and 'No'?", the answer is No.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum