Click to See Complete Forum and Search --> : Alert boxes


hungrydino
08-23-2003, 07:54 PM
How do I make an alert box that has a yes or no - preferably not ok or cancel although I don't know how to do that either - options.

Cheers - thanks,
Stephen

Exuro
08-24-2003, 12:04 AM
There isn't a way to make a Yes/No popup in JavaScript, but it is possible in VbScript. However, VbScript is IE-Only, so you have to have an alternative for non-IE browsers. Here's a little example I came up with:


<html>
<head>
<script type="text/vbscript">
<!--
' This is the code for the IE-only Yes/No message box
dim buttonClicked
buttonClicked = msgbox("Message",vbOkCancel,"Title")
msgbox buttonClicked
'-->
</script>
<script type="text/javascript">
<!--
// This is the alternate code for non-IE browsers
isIE = document.all&&(navigator.userAgent.indexOf("Opera")==-1)
if (!isIE) {
var buttonClicked = confirm("Message");
alert(buttonClicked);
}
//-->
</script>
</head>
<body>
</body>
</html>


The confirm("Message") is the JavaScript way of creating an ok/cancel popup. The msgbox("Message",vbOkCancel,"Title") is how you make a yes/no popup in VbScript. You can read a bit more about the msgbox function at w3schools:

http://www.w3schools.com/vbscript/func_msgbox.asp

Anyway, I hope that works for you!

Exuro
08-24-2003, 12:13 PM
Wow, I'm sorry. Why on earth did I use a vbOkCancel when the whole point of this was to create a yes/no? Anyway, the code should've been like this:

<html>
<head>
<script type="text/vbscript">
<!--
' This is the code for the IE-only Yes/No message box
dim buttonClicked
buttonClicked = msgbox("Message",vbYesNo,"Title")
msgbox buttonClicked
'-->
</script>
<script type="text/javascript">
<!--
// This is the alternate code for non-IE browsers
isIE = document.all&&(navigator.userAgent.indexOf("Opera")==-1)
if (!isIE) {
var buttonClicked = confirm("Message");
alert(buttonClicked);
}
//-->
</script>
</head>
<body>
</body>
</html>

Sorry about messing that up the first time!

hungrydino
08-24-2003, 03:00 PM
thanks a bunch

diamonds
08-24-2003, 03:53 PM
VB actually uses numbers to represent the values:
vbyesno stands for 32,
vbokcancel for 16 or somthing like that.
What happens is the browser decodes that into bitinary to read like this: 010001, the first numbar the if it is yes/no, the second if it is ok/cancel, the third the icon ect.
So you dont need to type vbyesno+vbquestion: you can type 33 or somthing else.

For the exact values, try this:
msgbox(vbYesNo,vbOk,"Title")
and the value of vbYesNo will appear in the popup.

PS: I dont know the exact values.

Exuro
08-24-2003, 05:36 PM
Yeah, I understand that Diamond. But, they have those Constants built into the launguage for a reason. It's much more clear what's going on when you see vbOkCancel in the msgbox function than if you were to see the number 1.

And actually, all the values are listed on the page I linked to in my reply earlier.