Javascript| News | data | Refresh/////////////by xxrl (Confucius Yue Cheng, Meng Yue take e)
Chinese: King Jianhua
Email:jjh_115@eyou.com
linkage, linkage, linkage .... Troubled a lot of netizens nerves, in the csdn-asp plate, always see netizens cry for help, save what? Linkage! Why linkage such attention, its practicality is justifiable, users can also be recognized, but if the data is large and interrelated, the problem comes, how to identify and show is a very distressed problem. Is there a good solution? The answer is yes, because we have ASP and JavaScript, haha, then let's get moving!
We want to get the data, since to achieve the effect of linkage, it is certain that the data is related, then we use such an example to illustrate our approach
Prepare the condition:
SQL SERVER 2000 Chinese Enterprise Edition, iis5.0+,ie5.0+, of course, it's best to have a good editor, VS. NET is good, of course, if you are a supporter of Notepad, then I have no way. L
We in the personnel management of the departmental level of linkage methods, understand the management of the departmental level can be defined as such, but also the definition of the actual enterprise rules, * * Chemical Plant/** System/** Department, for example, is
XX Chemical Plant/Marketing System/Marketing department, in the text, Firstorganization table corresponds to the "XX chemical plant", secondorganization corresponds to the "Marketing system", thirdorganization corresponding to the "marketing department"
In SQL SERVER 2000 to create a new two tables, or three tables, in order for us to play a greater function of linkage, we built three tables, hehe.
OK,ODBC, we have built, the database has been built, as for the configuration of the site, I think we all should know, here no longer stated. Here My Site IP is http://200.100.100.88 (internal network IP)
Finally began to write programs, good tired, poof, poof, just help my colleagues to move things, rest for a while, coffee-ing ...
Well, in order to facilitate the IIS of his old people, we are too lazy to knock on the extra letters, we are smart, not hard-working programmers, the programmer has been tired enough, but also not convenient for ourselves? Hey, I applaud, clap, faint, where's the firecracker? The child of what family is also bad good tube ... J
New Default.asp file, we are writing the following program,
Set up a database connection object,
Set Objconn=server. CreateObject ("Adodb.connection")
objconn. Open "Xxrl_ ODBC", "Xxrl_study", "Xxrl_study"
And then open the 3 datasets we're going to be working on.
Dim sql1,sql2,sql3
Sql1= "SELECT * from Firstorganization"
SQL2 = "SELECT * FROM Secondorganization"
SQL3 = "SELECT * FROM Thirdorganization"
'/////////////////////////Open first Organization library
Set Rs1=server. CreateObject ("Adodb.recordset")
Rs1. Open sql1,objconn,1,1
Set Rs2=server. CreateObject ("Adodb.recordset")
Rs2. Open sql2,objconn,1,1
Set Rs3=server. CreateObject ("Adodb.recordset")
Rs3. Open sql3,objconn,1,1
Build a Select type of HTTP control, which is included in the form form as follows:
' The initial value of the////////////////////control is read from the firstorganization, firstorganization in this case, only one of the data is XX Chemical factory code as follows:
Now we're going to build a second select control, in the second select control, we use the onchange function, and for a detailed explanation of this function, see MSDN. The code is as follows (included in the form):
OK, the second one is done, so let's build a third select also in the form form, as follows:
<select name=thirdorganization>
</select>
Don't forget to close the dataset Oh,
Rs1.close
Set rs1 = Nothing
Rs2.close
Set rs2 = Nothing
Rs3.close
Set Rs3 = Nothing
OK, the page elements are all ready, let's begin our real linkage tour.
This example uses ASP and JavaScript to interact with the data in the database, because we create a new script script before the form form, because we want to interact, so we have to write so that we can interact well
<%= "<script language=javascript>"%>
</script>
Then we can write our program in the script block.
Our basic operation is based on the two-level drop-down to draw three-level Drop-down, the second class we have taken out of the database, the following we want to take three-level organization data, as follows
<%= "<script language=javascript>"%>
<% ' ASP block
Dim sql_getthirdorganization
sql_getthirdorganization = "SELECT * from thirdorganization ORDER BY id DESC"
Set rs_getthirdorganization = Server. CreateObject ("Adodb.recordset") Rs_getthirdorganization.open sql_getthirdorganization,objconn,1,1
var id = ID; Index value of item selected for acceptance of level two menu
document.form1.thirdorganization.length=0; Initializes the length of the third-level menu, starting with the subscript 0
var i = 0;
Initializes the value of the text and Value property of the third level menu, the first parameter value is Text "--------", and the second is////////value null value
Loop array, comparing the number of the third dimension (parent ID) of the array with the numbers passed by the function.
for (i=0;i< temp;i++) {
if (related[i][2]==id) {/////////If equal, it is shown that a subset of the second-level organization is entered in the third level
and assigns the value of the subset (third level) to the third Select,
Document.form1.thirdorganization.options[document.form1.thirdorganization.length] = new Option (Related[i][1], Related[i][0]);
}
}
}
</script>
Finally at the end of the page do not forget to add objconn.close Oh, hehe
The main thing described above is a third select that is based on selecting a second select, so if we define a function in the third select control as follows:
This way, and then write a similar function in the script block, function content with the Changelocation function, is not achieved three-level linkage, so on and so on, oh, 10-level linkage can be done, but only trouble, of course, you can also use other methods, or a table to correspond to the algorithm , this casually, I This example is also from my actual development of a little experience accumulation, mainly for thinking clearly, for the people do not understand the program good maintenance, so will organize separate, because I never maintenance, hey.
Summer is over, hehe, wish you all good health! I wish the future of the Mid-Autumn Festival happy, I want to be a person in the field again.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.