VBScript and Simple Form Verification
With Visual Basic Scripting Edition, you can perform a lot of form processing work on the server, or do not work on the server.
This is a simple example of client verification. The result of the HTML code is a text box and a button. Use the following code to view Microsoft (R) Internet Explorer:Created pageYou will see a text box with buttons next to it.
<HTML><HEAD><TITLE>
Simple Verification</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Validate
Dim TheForm
Set TheForm = Document.forms("ValidForm")
If IsNumeric(TheForm.Text1.Value) Then
If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
MsgBox "
Enter 1
To 10
."
Else
MsgBox "
Thank you."
End If
Else
MsgBox "
Enter a number."
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>
Simple Verification</H3><HR>
<form id="ValidForm" action="nothing.asp" onsubmit="Validate(); return false;" language="Visual Basic Scripting Edition">
Enter 1
To 10
Between:<input name="Text1" TYPE="TEXT" class='9v'>
<input name="Submit" TYPE="Submit" VALUE="
Submit">
</form>
</BODY>
</HTML>
The difference between this text box and the VBScript page is thatValueAttribute is used to check the input value. TheValueProperty, the Code must reference the name of the text box.
The full name should be written every time the text box is referenced, that is, Document. ValidForm. Text1. However, when you reference the form control multiple times, follow these steps: declare a variable first, and then use the Set statement to import the form Document. validForm is assigned to the variable TheForm so that TheForm can be used. text1 references the text box. The general value assignment statement (such as Dim) is invalid and must be used.SetTo keep references to objects.
Use numbers
Note that the preceding example directly checks whether the input value is a number: Use the IsNumeric function to determine whether the string in the text box is a number. Although VBScript can automatically convert strings and numbers, it is always a good habit to detect sub-types of user input values and use conversion functions when necessary. When using the Value Attribute of the text box for addition operations, it should be explicitly converted to a number, because the plus sign (+) operator can not only perform addition operations, and can be connected to strings. For example, if Text1 contains "1" and Text2 contains "2", you will see the following results:
A = Text1.Value + Text2.Value
' A
For12
"A = CDbl(Text1.Value) + Text2.Value
' A
Is 3
Pass data back to the server after verification
The simple verification example uses a common button control. If you use the Submit control, all data will be immediately transmitted to the server, and the sample will not see the data for inspection. Avoid using the Submit control so that you can check data, but cannot Submit data to the server. If you want to submit data, you need to add another line of code, as shown below:
<SCRIPT LANGUAGE="VBScript"> <!--Sub Button1_nClick Dim TheForm Set TheForm = Document.ValidForm If IsNumeric(TheForm.Text1.Value) Then If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then MsgBox "
Enter 1
To 10
."
Else
MsgBox "
Thank you."
TheForm.Submit
'
The data is entered correctly and transmitted to the server. End If
Else
MsgBox "
Enter a number."
End If
End Sub
-->
</SCRIPT>
When the data is entered correctly, the Code callsSubmitMethod to transfer data to the server. The server processes the data, regardless of whether the data is correct or not, unless it is determined that the data is correct before it is passed to the server. You can findSubmitAll information about methods and other methods that can be found on the Microsoft (R) Web site (http://www.microsoft.com.
So far, you have only seen the standard HTML <FORM> object. Internet Explorer also allows you to create pages using all the functions of ActiveX (R) controls (formerly known as OLE controls) and Java (TM) objects.