请大家看一下我这段程序
<tr>
<TD HEIGHT="40" width="106">选择营业部</TD>
<TD HEIGHT="40" width="324">
<select size="1" name="reportag02" onchange="window.open(表.asp?jg=<%=jigou%>&glchu=<%=guanlichu%>&yyb=+this.options[this.selectedIndex].value,_self)">
<option value="%">全部</option>
<%
sql = " select distinct id,name from list where "
sql = sql & " col like "&guanlichu&"% group by id,name order by id "
Set glc = sqlconn.execute(sql)
Do until glc.Eof %>
<option value="<%=glc("id") %> "<% if glc("id")= yingyebu then%>selected<%end if %>><%=glc(1) &glc(0)%></option>
<%
glc.MoveNext
Loop
%>
</select>
</TD>
</tr>
我希望当该页面因为下拉框改变而刷新时,下拉框中选中项保持不变,但是现在,如果我选择name和id是相同的数字的选项时,if判断就会失效,该下拉框就会选择“全部”而如果选择name是汉子,id是数字的选项时,if判断就正常,请问这是什么原因。数据库中id和name字段都是char型。
<option value="<%=glc("id") %> "<% if glc("id")= yingyebu then%>selected<%end if %>><%=glc(1) &glc(0)%></option>
变量yingyebu在哪儿获取?
<option value="<%=glc("id") %> "<% if glc("id")= request("yingyebu") then%>selected<%end if %>><%=glc(1) &glc(0)%></option>
换成着一句:
<option value="<%=glc("id") %>" <% if glc("id")= yingyebu then%> selected<%end if %>><%=glc(1) &glc(0)%></option>
全部换成这样呢!我这样是可以的,表.asp更名为table.asp,最好不用中文:
<tr>
<TD HEIGHT="40" width="106">选择营业部</TD>
<TD HEIGHT="40" width="324">
<select size="1" name="reportag02" onChange=parent.location.href=this.form.select.options[this.form.select.selectedIndex].value,_self)">
<option value="%">全部</option>
<%
sql = " select distinct id,name from list where "
sql = sql & " col like "&guanlichu&"% group by id,name order by id "
Set glc = sqlconn.execute(sql)
Do until glc.Eof %>
<option value="table.asp?jg=<%=jigou%>&glchu=<%=guanlichu%>&yyb=<%=glc("id")%>" <% if glc("id")= yingyebu then%> selected<%end if %>><%=glc(1) &glc(0)%></option>
<%
glc.MoveNext
Loop
%>
</select>
</TD>
</tr>
得到选择的值,有两种情况做
一种是request,另一种是javascript document.all.selectname.options[]......
在判断语句都加上cstr这个函数试一下,比如:
if cstr(glc("id"))= cstr(yingyebu) then ^
变量yingyebu确定有值么?
<tr>
<TD HEIGHT="40" width="106">选择营业部</TD>
<TD HEIGHT="40" width="324">
<select size="1" name="reportag02" onchange="window.open(表.asp?jg=<%=jigou%>&glchu=<%=guanlichu%>&yyb=+this.options[this.selectedIndex].value,_self)">
<option value="%">全部</option>
<%
sql = " select distinct id,name from list where "
sql = sql & " col like "&guanlichu&"% group by id,name order by id "
Set glc = sqlconn.execute(sql)
response.write yingyebu&"ok"
Do until glc.Eof %>
<option value="<%=glc("id") %> "<% if glc("id")= yingyebu then%>selected<%end if %>><%=glc(1) &glc(0)%></option>
<%
glc.MoveNext
Loop
%>
</select>
</TD>
</tr>
看看输出什么?