The code for asp query xml does not refresh the page. The implementation method of the query is as follows:
<html>
<head>
<title>How to query without refreshing the page</title>
<meta http-equiv=Content-Type content=text/html; charset=gb2312>
</head>
<script language=javascript>
<!--Initialization, load the data in the data island into the list box-->
function loadinsel()
{
var employeeid,employeelastname; //Store employee ID and employee name respectively
root=document.all.xmlemployees.childNodes.item(0); //Return 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 obtained employeeid and employeelastname into select
if(employeeid!= && employeelastname!=){
option1=document.createElement(option);
option1.text=employeelastname;
option1.value=employeeid;
employeelist.add(option1);
}
}
}
<!--Initialization, retrieve data from the data island and load it into the list box-->
function findemployee(){
var employeelastname,employeeid; //Store employee name and employee ID respectively
employeelastname=;
employeeid=;
findtext=window.findcontent.value; //Get the search conditions
//Clear the 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 matching items
employeelastname=employee_temp; //Find employees with matching names
}
}
}
//Write qualified employee information into 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 query conditions:
<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 'username
pw= 'User password
databasename=northwind 'database name
set conn=server.CreateObject(adodb.connection)
conn.Open DRIVER=SQL Server;SERVER=&servername&;UID=&user&;pwd=&pw&;DATABASE=&databasename
set rs=server.CreateObject(adodb.recordset)
sql=Select employeeid,lastname from employees order by employeeid
rs.Open sql,conn%>
<!--Put the information in 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>
</html>
Use ASP's instr() function to detect whether a string contains the 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(&wstr1& does not contain &wstr2&)
end if
%>
-------------------
InStr function
-------------------
InStr([start, ]string1, string2[, compare])
【parameter】
The syntax of the InStr function has the following parameters:
part
illustrate
start
Optional parameters. For a numeric expression, sets the starting point for each search. If omitted, starts at the first character position. If start contains Null, an error will occur. If the compare parameter is specified, the start parameter must be present.
string1
Required parameters. Accepts a string expression to search for.
string2
Required parameters. The string expression to be searched for.
Compare
Optional parameters. Specify string comparisons. If compare is Null, an error will occur. If compare is omitted, the setting of Option Compare determines the type of comparison.
The ?compare parameter is set to:
constant
value
【describe】
vbUseCompareOption
-1
Use the Option Compare statement setting to perform a comparison.
vbBinaryCompare
0
Perform a binary comparison.
vbTextCompare
1
Perform a textual comparison.
vbDatabaseCompare
2
For Microsoft Access only, performs a comparison based on information in the database.
【return value】
Returns 0, 1, 2, -1 or Null, etc.
【Exception/Error】
none
DescriptionInStr([start, ]string1, string2[, compare])
Returns the first occurrence of a specified string within another string. In the string string1, search for string2 starting from start. When start is omitted, search from the beginning of string1. When not found, the function value is 0.
if
InStrreturn
string1 is zero length
0
string1 is Null
Null
string2 is zero length
Start
string2 is Null
Null
string2 not found
0
Find string2 in string1
location found
start > string2
0
【Example】
This example uses the InStr function to find the first occurrence of a string within another string.
Dim SearchString, SearchChar, MyPos
SearchString =XXpXXpXXPXXP ' The string being searched.
SearchChar = P ' To search for the string P.
' Starting from the fourth character, search by text comparison. The return value is 6 (lowercase p).
' Lowercase p and uppercase P are the same under text comparison.
MyPos = Instr(4, SearchString, SearchChar, 1)
' Starting from the first character, search using binary comparison. The return value is 9 (capital P).
' Lowercase p and uppercase P are different in binary comparison.
MyPos = Instr(1, SearchString, SearchChar, 0)
'The default comparison method is binary comparison (the last parameter can be omitted).
MyPos = Instr(SearchString, SearchChar) ' Return 9.
MyPos = Instr(1, SearchString, W) ' Return 0.