If you are using Internet Explorer then you would have
received a popup as soon as you came to this site. That was a VBScript MsgBox (message box), a popup window that can be called
using the MsgBox function. You can use this popup to display crucial information,
gather data, or just annoy your visitors!
VBScript MsgBox Creation
To create a simple message box you only need to supply the MsgBox function
with a string and this will be what is displayed on the popup prompt. Our
following example will popup with the message "Hello There!".
MsgBox "Hello There!"
This is the code for the popup box you see when you load this page.
VBScript MsgBox Arguments
While it is quite easy to create a MsgBox with a simple message, customizing your
MsgBox is quote complex. There are up to 4 optional arguments you can give the MsgBox
function bringing the grand total to 5 arguments!
However, only two of these options are that useful and they are:
- Button (Integer)- Allows you to set which buttons will be displayed on your popup. OK button is the default setting.
- Title (String)- Sets the title of the popup window, much like the HTML title tag sets the title of the browser window.
A complete listing of the button constants can be found at Microsoft's
In this example we will be creating a HTML button that creates a MsgBox with a message, a title and an OK and Cancel button when clicked.
For a review on HTML Buttons see our HTML Forms Tutorial.
MsgBox "Hello there!", 1, "Greeting Popup"
<input type="button" value="Click Me!" name="myPopup" />
Found Something Wrong in this Lesson?
Report a Bug or Comment on This Lesson - Your input is what keeps Tizag improving with time!