1. VBScript intro
  2. VBScript basics
  3. VBScript variables
  4. VBScript procedures
  5. VBScript popup boxes
  6. VBScript conditions
  7. VBScript loops
  8. VBScript arrays
  9. VBScript strings
  10. VBScript date & time
  11. VBScript for IE 11
  12. VBScript summary

VBScript popup boxes

VBScript provides a few popup boxes to interact with the user. More specifically, alert and prompt boxes.

This tutorial focuses on:

Displaying an alert box

An alert box is a box that appears with a message inside it and a title. The user will have to press the "OK" button or any other potential buttons that appear on the alert box to close it.

An alert box can be displayed using VBScript's MsgBox function together with the text to be displayed in the alert box, a title, and an integer indicating what kind of button or buttons should appear on the message box (0 for just an "OK" button, 1 for an "OK" and "Cancel" buttons).

MsgBox "text", num, "title"
<script type="text/vbscript"> <!-- Function aButton_OnClick() MsgBox "Message boxes are cool!", "0", "Hi, I am a message box" End Function --> </script> <input type="button" value="Click here for a message" name="aButton" />

Displaying a prompt box

A prompt box is used to get data from the user. A prompt box will appear with an "OK" button and a "Cancel" button. Different actions will occur depending on what button the user clicks. If the user clicks the "OK" button, the value entered into the prompt box will be set. If the user clicks the "Cancel" button, an empty string will be set.

A prompt box can be displayed using VBScript's InputBox function.

InputBox ("MessageToShow", "TitleOfPromptBox")
<script type="text/vbscript"> 'display a prompt box asking the visitor for their favorite color function promptButton_OnClick dim favColor favColor = InputBox("What is your favorite color?", "Favorite color") if favColor = "" then MsgBox("You did not specify your favorite color!") else MsgBox("Your favorite color is " & favColor) end if end function </script> <input type="button" value="Click here to specify your favorite color" name="promptButton" />
© Copyright 2013-2014 Landofcode.com
Terms of use | Privacy policy | Copyright information