Categories:
Partners
Web Hosting
We've partnered with HostGator for reliable, affordable hosting starting at $3.95/mon. Use coupon code "javascriptkit25" for 25% off any package.

Determining which button was pressed

What good are even the fanciest of buttons if we can't determine which button inside was pressed? In VBScript, we can obtain this information through the return value of the MsgBox() method:

returnvalue=MsgBox ("Incorrect",37,"Pop Quiz")

Here's a listing of the possible return values, and what they imply:

Return value Button Clicked Return value Button Clicked
1 Ok 5 Ignore
2 Cancel 6 Yes
3 Abort 7 No
4 Retry    

This example takes the user back one page if the "Retry" button is pressed:

<script language="VBscript">

returnvalue=MsgBox ("Incorrect",37,"Pop Quiz")
If returnvalue=4 Then
history.go(-1)
End If

</script>

Basic flow control

Considering the importance of flow control statements in virtually anything scripting, let's familiarize ourselves with at least the two most important ones syntax wise for VBScript:

//Basic If statement:
If time>0 Then
Distant=rate*time
End If
//If-else statement:
If time>0 Then
Distant=rate*time
Else
distant=0
MsgBox "Invalid time entry"
End If

Here's a popular example that uses an if-else statement in conjunction with MsgBox to ask for user confirmation before allowing he/she to enter a page:

<script language="VBscript">

Sub entrance_onClick
returnvalue=MsgBox ("You are about to enter a DHTML intensive site. Proceed?",52,"Greetings!")
If returnvalue=6 Then
window.location="http://www.dynamicdrive.com"
Else
window.location="http://www.yahoo.com"
End If
End Sub

</script>

<form>
<input type="button" name="entrance" value="Click here">
</form>

Copyright 1997-2014 JavaScript Kit. NO PART may be reproduced without author's permission.