注册 登录
编程论坛 ASP技术论坛

关于request.form问题(错误:函数需要字符串输入)

51684444 发布于 2008-06-09 18:11, 1476 次点击
Request 对象, ASP 0102 (0x80004005)
函数需要字符串输入。
/Untitled-5.asp, 第 13 行
我的意思是,在表单上输入年龄和岁数。根据输入表单里年龄和性比来判断输出小妹妹还是小弟弟等


<%
dim sex,age

if request.form (sex)="男" then
if request.form (age<8) then
response.Write("小弟弟")
else
if request.form (age>=8 and age<=15) then
response.Write("小男孩")
else
if request.form(age>=16 and age<=24) then
response.Write("小伙子")
else
if request.form(age>=25 and age<=45) then
response.Write("青年男子")
else
if request.form(age>=46 and age<=55) then
response.Write("中年男子")
else
if request.form(age>=56 and age<=80 )then
response.Write("老爷爷")
else
if request.form(age>80) then
response.Write("老寿星")
end if
end if
end if
end if
end if
end if
end if
else
if request.form (age<8) then
response.Write("小妹妹")
else
if request.form (age>=8 and age<=15) then
response.Write("小女孩")
else
if request.form (age>=16 and age<=24) then
response.Write("小姑娘")
else
if request.form(age>=25 and age<=45) then
response.Write("青年女子")
else
if request.form (age>=46 and age<=55) then
response.Write("中年女子")
else
if request.form(age>=56 and age<=80) then
response.Write("奶奶")
else
if request.form(age>80) then
response.Write("老奶奶")
end if
end if
end if
end if
end if
end if
end if
end if
%>



<form action="" method="post" >
<input name="age" type="text" value="" size="20">请输入内容

<br>
男<input name="sex" type="radio"value="男">
女<input name="sex" type="radio"value="女">
<br>
<input name="" type="submit" value="提交">
</form>
4 回复
#2
multiple19022008-06-09 19:05
<%
dim sex,age

if request.form (sex)="男" then  ' 写法错误。正确写法:if request.form("sex")="男" then
if request.form (age<8) then     ' 写法错误。正确写法:if request.form("age")<8 then
response.Write("小弟弟")

%>

建议你起码看几个别人写的程序,也别光看书,不然印象不深刻。

另外这么多if最好缩进一下,自己看着也清楚。
或者用select case语句:
select case true
  case age<8
       write "小弟弟"
  case age<...
       write ....
   ...
   case else
       write "千年的xx"
end select
#3
hmhz2008-06-10 11:15
小弟弟  呵呵
#4
516844442008-06-10 21:58
多谢二楼的指点。都是网上教程误人子弟。我真该多看看别人代码,我现在才知道IF还能缩进。看来我要学的还多呢
#5
ilovey42008-06-11 02:37
LZ多看点书吧
1