DelphiFAQ Home Search:

Have a Javascript popup display Yes/ No instead of Confirm/ Cancel


comments72 comments. Current rating: 4 stars (24 votes). Leave comments and/ or rate it.


I need to ask my web site's user a Yes/ No question. Currently I use JavaScript's confirm() function.
The return value is true (OK) or false (CANCEL).
The word CANCEL is misleading. I want to have the buttons say Yes/ No instead.
How can I do it?


Many people will tell you it is not possible, and that is true for standard Javascript.

However, I found the following which works at least in 32 bit Windows with IE (which often accounts for 95% of your site's users).

This solution uses vbscript's confirm() function.

No, it does not work in FireFox. FireFox will display Confirm/ Cancel.

<script language=javascript>

/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

function window.confirm(str)
    execScript('n = msgbox("'+str+'","4132")', "vbscript");
    return(n == 6);

@end @*/
var r = confirm("Can you do it?");

Content-type: text/html


You are on page 3 of 5, other pages: 1 2 [3] 4 5
2008-12-16, 03:01:06
anonymous from India  
thanks a ton buddy...I was searching for it long time..
2008-12-16, 05:33:58
anonymous from India  
thanks a ton buddy..I have been looking for this script for a long time...

2009-01-01, 03:25:18
Rony from India  
Great piece of code... Thanx
2009-02-10, 15:48:59   (updated: 2009-02-10, 15:49:31)
aman from United States  
The code is very good, helped me alot.. helpful and excellent post!
2009-02-10, 18:05:37
anonymous from Canada  
really impressed, thanks a ton
2009-03-05, 05:13:59
anonymous from India  
Excellent.. Thank u so much..
2009-04-09, 13:08:44
anonymous from United States  
You are so cool
2009-05-14, 23:34:28
anonymous from United States  
If you want a new line, use chr(10)+chr(13). It took me forever until my coworker suggested to try. It works.
2009-05-19, 03:27:09
anonymous from India  
This article is a great one. But i need one more requirement , is that possible to change the default selection of the button to NO rather than YES

Please help me to solve this issue
2009-05-24, 11:48:45
anonymous from India  
2009-06-05, 08:58:15
We need javascript in confirm pop window in yes or no event..dont use vb script ..for this ..event.
thanks Ezak
2009-06-08, 09:53:57
anonymous from United States  
You are awesome man!!!....Keep helping..:)
2009-07-09, 00:20:27
anonymous from India  
2009-07-10, 00:23:26   (updated: 2009-07-10, 00:37:29)
[hidden] from India  
great boss great.......
but still i am not understand about code inside

code to change button level

would u explane this code functionality please how it replace OK and Cancel label?

and i will be greatfull if u help me do do this confirmation with YES/NO button for FF

2009-08-14, 00:00:31   (updated: 2009-08-14, 00:02:32)
Hey dude!

Awesome piece of code.

Thanks alot

You are on page 3 of 5, other pages: 1 2 [3] 4 5



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: