It is really hard for me to get data from check boxes when I want to purchase a Web site online. Although I have been in contact with ASP for more than a year, I have never dealt with the check box. I am helpless. Finally, I finally solved the problem with the help of the search engine. Here is a brief summary. In the future, it will take less time for cainiao who are similar to me to encounter such problems.
Check box is a box that can be selected multiple times. The check box with the same name in the same form is considered as an array when the program obtains data. The obtained value is the value of the check box, the method for obtaining the check box is the same as that for obtaining other text boxes. form. For example, if we set 10 check boxes, 0-9 indicates a number. When creating a check box, we can name the value of each check box shuzi (or any other name that you think can be used, it is best not to use Chinese .), Set the value to 0-9 respectively.
Obtain the value. On the form action page, you only need to use request. the form ("shuzi") method can obtain the value selected by the user. For example, the user selects the response of 023. write (request. the result of form ("shuzi") is 1, 2, 3.
Data separation. Sometimes we want to split the data from these collections. This requires the split function. This is a built-in function of VB and can be called directly, it separates the data set passed by the check box into an array. The specific usage is split (expression, "separator"). In the value set of the check box, the Delimiter is '.
For example:
<%
Dim huzi, arri, STR,
Shuzi = request. Form ("shuzi ")
Arri = Split (shuzi ,",")
%>
To display the separation result, we still need to use a loop for each in ...... Next
For each in ...... Next (array loop), in the format
For each variable in array name
Program code
Next
'The variable here is the place where the array is stored and the custom variable.
For example, the above Code can be written
<%
Dim shuzi, arri, STR,
Shuzi = request. Form ("shuzi ")
Arri = Split (shuzi ,",")
For each B in arri %>
N = trim (B)
STR = STR & N & "& nbsp ;"
Response. Write (STR)
Next
%>
At this point, we can get the value of the check box selected by the user and display it.
Another problem is how to know the number of values selected by the user, that is, the length of the array. This is what we need to use the ubound function, we only need ubound (arri) + 1 to get the length of the arri array above. Because the "ubound method returns the maximum subscript of the array, so the length must be 1", we can write as follows:
<%
Dim shuzi, arri, STR,
Shuzi = request. Form ("shuzi ")
Arri = Split (shuzi ,",")
For each B in arri %>
N = trim (B)
STR = STR & N & "& nbsp ;"
Response. Write (STR)
Next
Lens = ubound (arri) + 1
Response. Write (lens)
%>
In this case, you have obtained and output the selected values and numbers from the check box.
I hope you can write for the first time. You are welcome to discuss this issue.