Wednesday, January 3, 2007

Javascript confirm() function with Yes/No buttons instead of Ok/Cancel

When you use Javascript confirm() function, the dialog box will display Ok/Cancel buttons, which sometime it doesn't make sense for Yes/No question. This post will fix that problem by using VBscript (MsgBox).

function window.confirm(message) {
execScript('answer = MsgBox("' + message + '","4132", "Confirmation")', 'VBScript');
return answer;
}

function question() {
if (confirm('Is it Yes/No question?') == 6) {
alert('Answer is Yes');
}
else {
alert('Answer is No');
}
}

No comments: