我有这个示例代码:
的VBScript:
dim conn,rs,sql, getval
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.Open dbconnection
sql = "Select * FROM tableDetails"
rs.Open sql, conn
getval = desc.value
if getval <> "" Then <---- I want to get value from input text with id of 'desc'
response.write("it has value")
end if
HTML:
<form method="POST" name="test" action="sample.asp">
<input type="text" id="desc" name="desc" value="<%=rs("desc")%>" />
</form>
如何从输入文本字段中获取值并将其传递给serverside变量?请帮忙..
答案 0 :(得分:0)
您没有正确地申请价值,但您可以轻松完成所需的工作。
dim conn,rs,sql, getval
Set conn = Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
conn.Open dbconnection
sql = "Select * FROM tableDetails"
rs.Open sql, conn
If not rs.eof Then 'always include this to make sure your DB query has results, otherwise you could get an error if the query is empty
getval = Request.Form("desc")
If getval<>"" Then
response.write("it has value")
End If
End If
另一种选择是从HTML页面获取值并将其重新插入数据库。每当你得到一个值时,总是清理它以保护你的数据库
getval= CleanInput(Request("desc")) 'clean it
SQL = "INSERT INTO tableDetails (desc) VALUES('"& getval &"');"
Function CleanInput(temp) '------------------------------------------
temp = Trim(Replace(temp,"'","`"))
CleanInput = temp
End Function'------------------------------------------