下拉列表框选择日期进行查询后,显示出来数据,但日期还会显示为当前日期,

Jiecb 2008-06-19 04:13:20
下拉列表框选择日期进行查询后,显示出来数据,但日期还会显示为当前日期.
比如偶想查询个税,当前日期是六月,查询4月或者2月时,数据都显示出相应月分的数据,但下拉框里的日期不是数据对应的日期,而是返回到当时日期,有什么办法显示查询相对应的数据日期?

以下是我的代码?!
---------------------------

<fieldset style="width:80%"><legend>上月个税查询</legend>
<table width="90%" border="0" cellpadding="0" cellspacing="0" bordercolor="#D4D0C8">

<form name="search" method="post" action="frmSearchTaxRate.asp">
<tr><input name="search" type="hidden" value="search">
<td height="18" align="center" width="25%">

<p align="right">年份<select name="selYear" size="1">
<!--<option value="<%=year(date) %>"><%=year(date) %></option>-->
<%
dim iPos
for iPos=1900 to 2050

if ipos=year(date) then
%>
<option selected=true value="<%=iPos%>"><%=iPos%></option>
<%
else
%>
<option value="<%=iPos%>"><%=iPos%></option>

<%
end if
next
%></select>

</td>
<td height="18" align="center" width="55%">

<p align="left">月份
<select name="selMonth" size="1">
<%

for iPos=1 to 12

if ipos= month(date) then

%>
<option selected=true value="<%=iPos%>"><%=iPos%></option>
<%
else
%>
<option value="<%=iPos%>"><%=iPos%></option>

<%
end if
next
%>
</select>

<input type="submit" value="查 询"></td>

<td align="center" width="15%" > </td>
</tr></form>

</table>
</fieldset>
------------------------------------------------------
...全文
310 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jiecb 2008-06-20
  • 打赏
  • 举报
回复
谢谢五楼的实现代码,我原来是第一次打开页面时是取当前的,麻烦就麻烦在查询了之后还是取当年的;
我照你的实现的代码,不知道是我弄错还是怎么样,第一次进入是当前代码,但查询后是1900和1月的时期...;
我是把
y=request.form("selyear")
if y="" then
y=year(date)
end if
放在实现年的那个下面,但出现了查询后日期跑到1900....
请指教一下.谢谢...

下面是数据库的读书代码.




set rs=server.CreateObject("ADODB.RecordSet")
search=request("search")

if search<>"" then
class1=request("selYear")
keyword=request("selMonth")-1

rs.Source="select * from pr_payroll t1 inner join pr_person t2 on t1.[it1]=t2.[it1] where t1.[it1]=" & session("userid") & " and t1.[year]=" & class1 & " and t1.[month]=" & keyword & " order by -t1.[month]"
else
rs.Source="select * from pr_payroll t1 inner join pr_person t2 on t1.[it1]=t2.[it1] where t1.[it1]=" & session("userid") & " order by -t1.[Month]"

end if
rs.Open rs.Source,conn,1,1
if rs.eof then
response.write("查询无数据!")
response.end()
else
.................(后备省略)
zhangjg2124 2008-06-19
  • 打赏
  • 举报
回复
同意楼上!
楼主你查询的是哪年哪月,在新的页面把年月得到然后让选择列表中相应的年月选中就好了。
如果是第一次访问,让默认为当前年月就行了。
xxwood 2008-06-19
  • 打赏
  • 举报
回复
2,3楼的看错代码了。
楼主你只贴了form里的代码,上面应该有两句取值的代码吧。
y=request.form("selyear")
m=request.form("selmonth")
你加一段:
if y="" then
y=year(date) '意思是说第一次打开此页面时肯定取不到selyear的值,所以就取当前年
end if
if m="" then
m=month(date)
end if
然后把你form代码里的if ipos=year(date) then 改成if ipos=y then ,把 if ipos= month(date) then 改成 if ipos= m then ,OK就这样。这种代码我天天写。。。真的很罗嗦。。。
Jiecb 2008-06-19
  • 打赏
  • 举报
回复
二楼的,还是那样,显示查询后还是显示当前的日期;
三楼,能否把实现写出来看一下?谢谢.


<body onload="sss()">


<select name="select1">
<option value="1">1月 </option>
</select>


function sss()
{
指定select1的显示值
}
--------------不是那么明白你的实现,好像跟我原来的差不多?!只是定义个函数来存日期?

egg_server 2008-06-19
  • 打赏
  • 举报
回复
<body onload="sss()">


<select name="select1">
<option value="1">1月</option>
</select>


function sss()
{
指定select1的显示值
}
yanniu008 2008-06-19
  • 打赏
  • 举报
回复
把你这个下拉框的植放到一个session变量中,进入页面的时候判断这个值是否为空。
如果不空的就这样:

<select name="tax">
<option value="<%=session("tax")%>"><%=session("tax")%></option>
</select
jacklinchen 2008-06-19
  • 打赏
  • 举报
回复
<fieldset style="width:80%"> <legend>上月个税查询 </legend>
<table width="90%" border="0" cellpadding="0" cellspacing="0" bordercolor="#D4D0C8">

<form name="search" method="post" action="frmSearchTaxRate.asp">
<tr> <input name="search" type="hidden" value="search">
<td height="18" align="center" width="25%">

<p align="right">年份 <select name="selYear" size="1">
<!-- <option value=" <%=year(date) %>"> <%=year(date) %> </option>-->
<%
dim iPos
for iPos=1900 to 2050

if trim(ipos)=trim(year(date)) then
%>
<option selected value=" <%=iPos%>"> <%=iPos%> </option>
<%
else
%>
<option value=" <%=iPos%>"> <%=iPos%> </option>

<%
end if
next
%> </select>

</td>
<td height="18" align="center" width="55%">

<p align="left">月份
<select name="selMonth" size="1">
<%

for iPos=1 to 12

if cint(ipos)= cint(month(date)) then

%>
<option selected value=" <%=iPos%>"> <%=iPos%> </option>
<%
else
%>
<option value=" <%=iPos%>"> <%=iPos%> </option>

<%
end if
next
%>
</select>

<input type="submit" value="查 询"> </td>

<td align="center" width="15%" >  </td>
</tr> </form>

</table>
</fieldset>

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧