vbscript| function | Interactive |vbscript| function | interaction
First, let's look at a piece of code like this:
<HTML>
<HEAD><TITLE> a simple home </TITLE>
<script language= "VBScript" >
<!--
Sub Button1_onclick
MsgBox "Welcome"
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3> a simple home </H3><HR>
<form><input name= "Button1" type= "button" value= "click here" ></FORM>
</BODY>
</HTML>
This is achieved when the click of the button, pop-up message box, show welcome
which
A sub defines a procedure that contains two parts:
Button1 is the button name (obtained from the Name property in the <INPUT> tag)
OnClick is the event name, which is the Button1 onclick event where two parts are connected with (_)
Together, click the button, Internet Explorer to find and run the appropriate event procedure, that is, Button1_onclick
<input name= "Button1" type= "button"
Value= "Click here" onclick= ' MsgBox "Welcome" ' >
The function call is enclosed in single quotes, and the string of the MsgBox function is enclosed in double quotes. Just use a colon (:) Delimited statement, you can make the
With more than one statement.
<script language= "VBScript" event= "OnClick" for= "Button1"
<!--
MsgBox "Welcome"
;
</ Script>
This method specifies events and controls in the <SCRIPT> tag, so there is no need to use sub and End Sub statements
Further implementation of simple verification
<HTML>
<HEAD><TITLE> Simple Validation </TITLE>
<script language= "VBScript" >
<!--
Sub Button1_onclick
Dim theform
Set theform = Document.validform
If IsNumeric (TheForm.Text1.Value) Then
If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > Then
MsgBox "Please enter a number from 1 to 10." "
Else
MsgBox "Thank you." "
End If
Else
MsgBox "Please enter a number. "
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3> Simple Validation </H3><HR>
<form name= "ValidForm" >
Please enter a number from 1 to 10:
<input name= "Text1" type= "TEXT" size= "2" >
<input name= "button1" type= "button" value= "Submit" >
</FORM>
</BODY>
</HTML>
The Value property of the text box in the simple sample of this text box and VBScript page is used to check the input values. To use the text box
Value property, the code must refer to the name of the text box.
Each time you reference a text box, you should write the full name, that is, Document.ValidForm.Text1. However, when you reference a form control more than once, you can
Follow these steps: Declare a variable first, and then use the SET statement to document.validform the form (the ID of the form)
To the variable theform, so that you can use the Theform.text1 reference text box. General assignment statements (for example, Dim) are not here
, you must use Set to keep a reference to an object.
Pass data back to the server after further validation
<HTML>
<HEAD><TITLE> Simple Validation </TITLE>
<<script language= "VBScript" >
<!--
Sub Button1_onclick
Dim theform
Set theform = Document.validform
If IsNumeric (TheForm.Text1.Value) Then
If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > Then
MsgBox "Please enter a number from 1 to 10." "
Else
MsgBox "Thank you." "
Theform.submit
End If
Else
MsgBox "Please enter a number. "
End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3> Simple Validation </H3><HR>
<form name= "validform" action= "page to submit" >
Please enter a number from 1 to 10:
<input name= "Text1" type= "TEXT" size= "2" >
<input name= "button1" type= "button" value= "Submit" >
</FORM>
</BODY>
</HTML>
In Sub, theform.submit a sentence to upload the form's contents to the server side
There are several points to pay attention to, I am in the test when the Name= "button1" changed to Name= "Submit" program error, the reason may be
Because submit is a reserved word
Similarly, if type= "button" is changed to type= "Submit", the data will be uploaded to the server side regardless of the validation results.