ASP query XML code does not refresh the page Query method _ Application Skills

Source: Internet
Author: User
Tags lowercase
The following are the referenced contents:
<title> ways to not refresh page queries </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<script language= "JavaScript" >
<!--initialization, loading data into a list box in the data island-->
function Loadinsel ()
{
var employeeid,employeelastname; Store employee ID and employee name separately
Root=document.all.xmlemployees.childnodes.item (0); Returns the first element--employee
for (i=0;i<root.childnodes.length;i++) {
Getnode=root.childnodes (i); Get a child node of Empolyee
Employeeid=root.childnodes (i). getattribute ("Emid");/Get Employee ID
for (j=0;j<getnode.childnodes.length;j++) {
Employeeinf=getnode.childnodes (j). NodeName;
if (employeeinf== "LastName") {
Employeelastname=getnode.childnodes (j). Text; Get Employee Name
}
}
Write the resulting EmployeeID and employeelastname into the Select
if (employeeid!= "" && employeelastname!= "") {
Option1=document.createelement ("option");
Option1.text=employeelastname;
Option1.value=employeeid;
Employeelist.add (Option1);
}
}
}
<!--initialization, retrieving data from the data island, loading the list box-->
function Findemployee () {
var Employeelastname,employeeid; Store employee name and employee ID separately
Employeelastname= "";
Employeeid= "";
Findtext=window.findcontent.value; Get a search condition
Clear list Box
Employeecount=employeelist.length
for (i=employeecount-1;i>=0;i--) {
Employeelist.remove (i);
}
Root=window.xmlemployees.childnodes (0);
for (i=0;i<root.childnodes.length;i++) {
Getitem=root.childnodes (i); Get a child node of Empolyee
Employeeid=root.childnodes (i). getattribute ("Emid"); Get Employee ID
for (j=0;j<getitem.childnodes.length;j++) {
if (Getitem.childnodes (j). nodename== "LastName") {
Employee_temp=getitem.childnodes (j). Text;
if (Employee_temp.indexof (FindText)!=-1) {//Find match
Employeelastname=employee_temp; Find the employee whose name matches
}
}
}
Write the qualified employee information into the Select
if (employeeid!= "" && employeelastname!= "") {
Option1=document.createelement ("option");
Option1.value=employeeid;
Option1.text=employeelastname;
Window.employeelist.add (Option1);
Employeeid= "";
Employeelastname= "";
}
}
}
</script>
<body bgcolor= "#FFFFFF" text= "#000000" onload= "Javascript:loadinsel ()" >
<table width= "80%" border= "1" >
<tr>
<td> Please enter the query criteria:
<input type= "text" name= "Findcontent" >
<input type= "button" Name= "Submit" value= "Find" onclick= "Javascript:findemployee ()" >
</td>
</tr>
<tr>
<td> Query Results:
<select name= "EmployeeList" >
</select>
</td>
</tr>
</table>
<?xml version= "1.0" encoding= "gb2312"?>
<%
Servername= "wyb" ' Server name
user= "sa" user name
pw= "" ' User password
Databasename= "Northwind" database name
Set Conn=server. CreateObject ("Adodb.connection")
Conn. Open "Driver=sql Server; Server= "&servername&"; Uid= "&user&";p wd= "&pw&";D atabase= "&databasename
Set Rs=server. CreateObject ("Adodb.recordset")
Sql= "Select Employeeid,lastname from Employees order BY EmployeeID"
Rs. Open sql,conn%>
<!--put information from the database into the data island-->
<xml id= "Xmlemployees" >
<employee>
<%do While not rs.eof%>
<employeeitem emid= "<%=rs (" EmployeeID ")%>" >
<lastname><%=rs ("LastName")%></lastname>
</employeeitem>
<%rs.movenext%>
<%loop%>
</employee> </xml>
<%rs.close
Set rs=nothing
%>
</body>
Use the ASP's InStr () function to detect if a string contains a specified string
<%
Dim WSTR1,WSTR2
wstr1= "Hello world!"
Wstr2= "O"
If InStr (WSTR1,WSTR2) >0 Then
Response.Write ("&wstr2&" exists in "&wstr1&")
Else
Response.Write ("&wstr2&" is not included in "&wstr1&")
End If
%>
--------------------
InStr function
--------------------
INSTR ([Start,]string1, string2[, compare])
Parameters
The syntax for the INSTR function has the following arguments:
Part
Description
Start
Optional parameters. is a numeric expression that sets the starting point for each search. If omitted, starts at the position of the first character. If start contains Null, an error occurs. If you specify a compare parameter, you must have the start argument.
String1
Necessary parameters. The string expression that accepts the search.
string2
Necessary parameters. The string expression being searched for.
Compare
Optional parameters. Specifies a string comparison. If compare is Null, an error occurs. If the setting of the Compare,option compare is omitted, the type of comparison is determined.
The Compare parameter is set to:
Constant
Value
Description
Vbusecompareoption
-1
Performs a comparison using the option Compare statement setting.
Vbbinarycompare
0
Performs a binary comparison.
vbTextCompare
1
Performs a comparison according to the original text.
Vbdatabasecompare
2
Applies only to Microsoft Access, which performs a comparison based on information in the database.
"Return value"
Returns 0, 1, 2,-1, or null.
"Exception/Error"
No
Description InStr ([Start,]string1, string2[, compare])
Returns the position in which the specified string appears first in another string. In the string string1, look for string2 from start, omitting the start from the string1 header. When not found, the function value is 0.
If
InStr return
String1 is zero length
0
String1 is Null
Null
string2 is zero length
Start
String2 is Null
Null
String2 can't find it.
0
Find string2 in string1.
Location found
Start > string2
0
Example
This example uses the INSTR function to find the position of the first occurrence of a string in another string.
Dim searchstring, SearchChar, MyPos
SearchString = "xxpxxpxxpxxp" is a searched string.
SearchChar = "P" ' to find the string ' P '.
' Start with the fourth character and find it in text comparison. The return value is 6 (lowercase p).
' Lowercase p and uppercase p are the same under text comparisons.
MyPos = Instr (4, SearchString, SearchChar, 1)
' Open from the first character, to be found in binary comparison. The return value is 9 (capital P).
' Lowercase p and uppercase p are different from binary comparisons.
MyPos = Instr (1, searchstring, SearchChar, 0)
The default alignment is a binary comparison (the last argument can be omitted).
MyPos = Instr (searchstring, SearchChar) ' returns 9.
MyPos = Instr (1, SearchString, "W") ' returns 0.
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.