/    Sign up×
Community /Pin to ProfileBookmark

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

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ShampieApr 30.2003 — 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..
Copy linkTweet thisAlerts:
@luizahaauthorMay 01.2003 — 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
Copy linkTweet thisAlerts:
@requestcodeMay 01.2003 — 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?omsg("Yes")' class='linkstyle'>Yes</a>&nbsp &nbsp<a href='javascript?omsg("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?oFormbox('Are you sure?')">Click Me for a Confirm Box</a><br>

</center>

</body>

</html>
×

Success!

Help @luizaha spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...