vbscript| check box | Control This two days to see a friend asked the HTML inside the various controls how to use the script to operate, now I also summed up. Because of the project reason, many programs are written in VBScript, interested friends can be changed into JavaScript, then don't forget to share Ah, alive.
OK, cut to the theme, now introduce:
Today I'll explain the number of checked boxes and the values of the selected check boxes using VBScript.
When a list is generated, such as a list of order orders, a check box may be placed in front of each order to provide functionality such as bulk deletion, distribution, etc. Generally, the value of each check box is the value of the primary key that should be recorded, such as the order number. In the implementation of the deletion, distribution, and other functions, you should know that a few check boxes, these checkboxes correspond to what values, the following is the method.
The program is divided into three parts:
First, judge whether the selected checkbox is one or more
The main idea is that when there are multiple check boxes with the same name, but the ID is different, the example CheckBox control name is Chktest, then it will be called as an array, for example, there are three check boxes named Chktest,id respectively is CHKTEST1,CHKTEST2,CHKTEST3, The checked property for the three check boxes is written like this: Chktest (0). Checked, Chktest (1). Checked, Chktest (2). Checked (array zero-based); And when there is only one check box, Chktest.checked can be used directly. This determines that for a number of different (one or more), only a different method can be used to get the check box information. Because when there are multiple controls with different IDs with the same name, the control has the property "control name. Type", and this read-only property can be equal to any string, that is, the control name. Type = "Any string" constant is true. Of course, this is only true for the property of the control name. Type, otherwise the constant is false, so that the check box in the list is single or multiple. The procedure is as follows:
'*************************************************
' < function name >
' Gfis_arraytest (obj)
' < function >
' To determine whether a selected checkbox is one or more
' < parameters >
' CheckBox object Name
' < return value >
' True
' False
' < notes >
' Created on mar.15th.2004 by AITD
'*************************************************
function Gfis_arraytest (obj)
On Error Resume Next
If Obj.type = "Flag" Then
Gfis_arraytest = True
Else
Gfis_arraytest = False
End If
End Function
Second, check the screen check box to choose whether to meet the requirements
The so-called whether to meet the requirements of the meaning is, for example, the deletion of the time to choose at least one record, the correct time to choose and can only select a record, as for the other, what can only choose 5, can only choose 10, and so on, the following procedures to change the following line. Don't forget what you just said, only one check box is different from the one with multiple check boxes.
'******************************************************
' < function name >
' Gfchkcheckbox ()
' < function >
' Check the screen checkbox to see if the selection meets the requirements
' < parameters >
' obj: corresponding checkbox control
' Flag: Check rule: 0 can have multiple selected
' 1 can only have one being selected
' Name: Information that prompts the user for an error in the control
' < return value >
' True
' False
' < notes >
' Created on mar.15th.2004 by AITD
'******************************************************
function Gfchkcheckbox (obj,flag,name)
Dim I
Dim J
Gfchkcheckbox = False
i = 0
j = 0
' If the object does not exist
If IsNull (obj) Then
MsgBox "Please select a + name +". "' Please select an object
Gfchkcheckbox = False
Exit function
End If
' Object has only one
If not gfis_arraytest (obj) Then
If obj.checked = False Then
MsgBox "Please select a + name +". "' Please select an object
Gfchkcheckbox = False
Exit function
Else
Gfchkcheckbox = True
Exit function
End If
End If
' If more than one object exists
For i = 0 to (obj.length-1)
If obj (i). Type = "checkbox" Then
If obj (i). Checked = True Then
j = j + 1
End If
End If
Next
If j = 0 Then
MsgBox "Please select + Name +". "' Please select an object
Gfchkcheckbox = False
Exit function
End If
If J = 1 Then
Gfchkcheckbox = True
Exit function
End If
If J > 1 Then
If flag = 1 Then
MsgBox "Only one" + name + "can be selected." "' Only one object can be selected
Gfchkcheckbox = False
Exit function
Else
Gfchkcheckbox = True
Exit function
End If
End If
End Function
Third, the value of the check box is obtained
For the convenience of later processing, the important information is often kept in the Value property of the check box for later use. The following program ^|^ the value of the selected check box into a string and returns with the spacer character "".
'*************************************************
' < function name >
' Gfgetcheckboxvalue (obj)
' < function >
' Gets the value of the selected checkbox
' < parameters >
' CheckBox object Name
' < return value >
' The value of the selected checkbox
' < notes >
' Created on mar.15th.2004 by AITD
'*************************************************
function Gfgetcheckboxvalue (obj)
Dim strvalue
Dim intcounter
Dim i
strvalue = ""
intcounter = 0
' If the object does not exist
If IsNull (obj) Then
Gfgetcheckboxvalue = strvalue
Exit function
End If
' If the object is a
If not gfis_arraytest (obj) Then
If obj.checked = False Then
Gfgetcheckboxvalue = strvalue
Exit function
Else
Gfgetcheckboxvalue = Obj.value
Exit function
End If
End If
' If the object is multiple
For i = 0 to Obj.length-1
If obj (i). Checked = True Then
If intcounter > 0 Then
strvalue = strvalue & "^|^" & CStr (obj (i). Value)
Else
strvalue = CStr (obj (i). Value)
End If
intcounter = intcounter + 1
End If
Next