在ASP中如何使用按钮!该按钮调用一个函数,达到保存表单内容到数据库的目的!
---------------------------------------------------------------
1<input type="submit"/>
---------------------------------------------------------------
要保存数据库就必须提交表单,提交表单使用楼上的提交按钮就可以。
---------------------------------------------------------------
提交到本页就可以
---------------------------------------------------------------
action设空
1<form action="" method="post" name="form1">
2<input type="submit"/>
3</form>
---------------------------------------------------------------
不用提交到本页也行,保存那页做一个转向也可以
在保存的那个页,最后加上
response.redirect "提交页"
提交到本页也可以,就是在本页完成保存的工作
form 的action="" 然后在程序开始判断
if request("按妞name")="按妞的值" then
request.form()...
........
保存
end if
显示提交页面
........
---------------------------------------------------------------
Entrance.asp
1<html>
2<body>
3<form name="frm">
4<table>
5<tr>
6<td><input name="txtName"/></td></tr>
7<tr>
8<td><input name="txtPassword"/></td></tr>
9<tr>
10<td><input onclick="save()" type="button" value="保存"/></td>
11</tr>
12</table>
13<script language="vbscript">
14sub save()
15frm.action="save.asp"
16frm.submit
17end sub
18</script>
19</form>
20</body>
21</html>
2.save.asp
.
.
conn.connectionstring="...."
conn.open
conn.execute "insert into user values('" & request("txtName") & "','" &request("txtPassword") & "'" )
---------------------------------------------------------------
写错了:
conn.execute "insert into user values('" & request("txtName") & "','" &request("txtPassword") & "' )"
---------------------------------------------------------------
1.把按钮放在表单外边吗?
可以
2.
Entrance.asp
1<html>
if request("flag")="save" then
.
.
conn.connectionstring="...."
conn.open
conn.execute "insert into user values('" & request("txtName") & "','" &request("txtPassword") & "'" )
.
.
..
end if
1<body>
2<form name="frm">
3<table>
4<tr>
5<td><input action="" name="txtName"/></td></tr>
6<tr>
7<td><input name="txtPassword"/></td></tr>
8<tr>
9<td>
10<input name="flag" type="hidden"/>
11<input onclick="save()" type="button" value="保存"/></td>
12</tr>
13</table>
14<script language="vbscript">
15sub save()
16frm.flag.value="save"
17frm.submit
18end sub
19</script>
20</form>
21</body>
22</html>
2.save.asp
---------------------------------------------------------------
把
1<input onclick="save()" type="button" value="保存"/>
这句写到
1<body></body>
以内的任何地方