用asp产生select下拉列表后,在客户浏览器中用javascript对其进行排序,这段排序程序却不起作用不知什么原因
请看下面的asp页面文件,其中javascript只循环了5次,产生的select代码改为其它的也一样,如果在设计时静态加入select列表中,那么,那段javascript就会正常执行,不信可以试一试,如果哪位知道原因望知之
___________________________________________________________________
<%@ Language=VBScript %>
<%Response.Expires =0 %>
<!--#INCLUDE FILE="share/conn.asp"-->
<html>
<head>
<title>test</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<select name="category_name" >
<%
function getNodePath(p_id)
dim rs,sqlstr,id,str
id=p_id
getpath=""
str=""
set rs=server.createobject("adodb.recordset")
do while true
sqlstr="select product.name,product_bom.* from product,product_bom " & _
"where product_bom.subdep_id=" & id & " and product_bom.subdep_id=product.id"
set rs = conn.Execute (sqlstr)
if rs.eof then exit do
str= "\" & rs("name") & str
if rs("dep_id")=1 then exit do
id=rs("dep_id")
rs.close
loop
rs.close
set rs=nothing
getNodePath=str
end function
dim rs,rscnt,sql,sqlcnt,str
str=""
set rs=createobject("adodb.recordset")
set rscnt=createobject("adodb.recordset")
sql="select product_bom.subdep_id from product,product_bom " & _
"where product_bom.subdep_id=product.id " & _
" and product.price is null"
rs.open sql,conn
do while not rs.eof
sqlcnt="select count(*) as p_count from product,product_bom where dep_id=" & _
rs("subdep_id") & " and product.id=product_bom.subdep_id and product.price is null"
rscnt.open sqlcnt,conn
if rscnt("p_count")=0 then
%>
<option value=<%=rs("subdep_id")%>><%=getNodePath(rs("subdep_id"))%></option>
<%
end if
rscnt.close
rs.movenext
loop
set rscnt=nothing
rs.close
set rs=nothing
%>
</select>
</form>
<script language="JavaScript">
function category_sort()
{
var items=document.all("select").options;
var i,j,temp;
document.write("items.length="+items.length+"<br>");
for(i=0;i<items.length-1;i++)
{
for(j=i+1;j<items.length;j++)
{
if(items[i].text>items[j].text)
{
temp=items[i].value;
items[i].value=items[j].value;
items[j].value=temp;
temp=items[i].text;
items[i].text=items[j].text;
items[j].text=temp;
}
}
}
}
category_name(();
</script>
</p>
</body>
</html>