Have a Javascript popup display Yes/ No instead of Confirm/ Cancel
26 comments. Current rating: (6 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-11-13, 15:04:34
anonymous from United States
I really need help on this. What's the full code ? I am getting error-
I have following inside the 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 @*/
function confirmSubmit()
{
var agree=confirm('Are you sure you wish to continue?');
if (agree)
return true ;
else
return false ;
}
</script>
And I am calling
<input type='Submit' name='Delete' value='Delete' onClick='return confirmSubmit()'>
and getting error. Can you please show the correct way.
2007-11-13, 15:35:31
anonymous from United States
Never Mind I got it working but Yes option is working properly but no button is not behaving properly. It's acting like yes button. Any idea?
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 ?