DelphiFAQ Home Search:

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


comments66 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
2009-08-25, 21:43:16
anonymous from China  
realy good.Thanks a lot.
2009-09-18, 06:41:51
anonymous from India  
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.Transitional/ /EN'>
<script language='JavaScriptype= 'text/javascript'>

</head> t;
<a href='#' onClick='retushowConfirm( )'>click</a>
2009-10-01, 13:39:16  
it works fine with IE(Because it supports Vb Script) but not with Firefox or other browser which does not support vb script
2009-10-27, 17:00:27
[hidden] from United States  
What's the syntax to get a new line? \r\n results to unterminated string constant error. Somebody posted here to use chr(10)+ chr(13). How do you do that? Thanks!
2009-12-02, 04:02:33
tapsel from Switzerland  
Exactly what I needed, and so simple! Thanks a lot!
2009-12-17, 03:04:29
Ell from Malaysia  
I think it doesn't work on:
1. Google Chrome
2. Safari 4.0.2 (530.19.1)
3. FireFox version 3.5.3
4. Opera version 10.00
2010-01-23, 12:37:48
anonymous from Italy  
good! very good!!!
2010-02-12, 02:46:18
anonymous from India  
Can some one let me know how to remove the 'VBScript' displayed as title ?
2010-02-19, 18:55:41
[hidden] from United States  

2010-03-09, 06:41:01
anonymous from India  
2010-03-15, 23:31:53
anonymous from India  

2010-03-22, 01:22:12
anonymous from Bangkok, Thailand  
2010-03-28, 20:08:41
anonymous from United States  
2010-04-06, 07:45:59
jojo from India  
<p> Can you do it?' </p>
<input type = 'button' id = 'ybutton' value = 'Yes' onclick = 'buttonwhich('You pressed YES')'>
<input type = 'button' id = 'nbutton' value = 'No' onclick = 'buttonwhich('You pressed NO')'>
<input type ='text' id = 'answerbox'>

<script type = 'text/javascript'>
function buttonwhich(message) {
document.getElementById('answerbox').value = message;
2010-04-13, 05:19:46
[hidden] from United States  
Hi.. It helped me a lot..
Is there any way to remove or Hide the 'VBScript:' that is displayed on the header of the alert?
Please Help.. Thanks in Advance
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: