VBScript
VBScript introduction
VBScript basics
VBScript variables
VBScript procedures
VBScript popup boxes
VBScript conditions
VBScript loops
VBScript arrays
VBScript strings
VBScript date & time
VBScript summary

Programming

Programming intro
Java

Markup

First webpage guide
HTML
XHTML

Browser scripting

Javascript
AJAX

Server scripting

PHP
ASP

Making money online

Make money online

VBScript popup boxes

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

NOTE: Remember that VBScript code only works in Internet Explorer or Internet Explorer based browsers such as SlimBrowser. If you are using any other browser to view this page, the VBScript code will not execute. If you are using Firefox, download the IETab extension to be able to view the output of code written in VBScript inside Firefox.

This lesson 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).

Syntax:

MsgBox "text", num, "title"

Example:

<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" />

Output:



The above example will display an alert box with the text "Message boxes are cool!" inside it, the title "Hi, I am a message box", and just an "OK" button.

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.

Syntax:

InputBox ("MessageToShow", "TitleOfPromptBox")

Example:

<script type="text/vbscript">
<!--

	'display a prompt box asking the visitor for their favorite color
	'set the message in the prompt box to "What is your favorite color?"
	'and set the title of the prompt box to "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" />

Output:



Practice

Online code editor
Practical examples
Practical exercises
Step-by-step tutorials

Reference

Terms glossary
Reference material

Rate this site

Rate this site
Visitor comments