Have a Javascript popup display Yes/ No instead of Confirm/ Cancel
56 comments. Current rating: (19 votes). Leave comments and/ or rate it.
Question:
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?
Answer:
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?");
alert(r);
</script>
Any confirmation in same page, will appear with Yes/No button... Great !!
Keywords:
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';
Form1.submit();
}
else
{
document.getElementById('txtTemp').value = 'cancel';
window.history.back;
}
}
}
</script>
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 ?
thanks
2008-02-14, 09:01:18
arun.obappa@gmail.com 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.