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 1 of 5, other pages: [1] 2 3 4 5
2006-12-22, 07:40:16
anonymous from Belgium  
You're brilliant!
2007-04-11, 00:18:27
anonymous from Thailand  
Thank U .It works well
but how can I get a new line
When I use '\n' in my message(str)
It show an error 'Unterminated string constant'
2007-07-27, 03:42:18
anonymous from Calcutta, India  
Excellent piece of code!!!!

Cheers :-)
2007-09-05, 08:32:56
anonymous from Romania  
You saved me :).
And it is such a simple code...
2007-11-07, 07:49:09   (updated: 2007-11-07, 07:50:25)
anonymous from United Kingdom  
Great help thanks.

> Is there a way to get it to work on an onClick vs. window load?
Remove these lines:
var r = confirm('Can you do it?');

Use as:
OnClick='confirm('Can you do it?');'
Note that speach marks don't display in this posting.
2007-11-13, 00:31:53
anonymous from Kuala Lumpur, Malaysia  
This code very nice.
Thanks a lot =)

Add this in <Head> tag:

<script language=javascript>
/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

function window.confirm(str)
execScript('n = msgbox(''+str+'','4132')', 'vbscript');
return(n == 6);
@end @*/

Any confirmation in same page, will appear with Yes/No button... Great !!

2007-12-03, 17:57:15
[hidden] from Indonesia  
        <script language='javascript'>
            function confirmExt()
                if (Form1.document.getElementById('txtTemp').value == 'run')
                    if(window.confirm('Are you sure want to change this file extention? Please be aware that changing the extension will affect the file readability.'))
                        document.getElementById('txtTemp').value = 'change';
                        document.getElementById('txtTemp').value = 'cancel';

anyone can help me ?
i use this javascript. it work in IE but in FF is not work. anything wrong or what i must to set to work in FF ?

2008-02-14, 09:01:18 from United States  
But this code shows the title bar of the confirm dialog box 'VBSCRIPT: Confirm'. If I need to remove the 'VBSCRIPT' what do I need to do.

Please find the screen shot attached.
You are on page 1 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: