-
very easy ASP question
ok, i''ve only just started messing about with ASP, so forgive this dumb question :)
i have an asp page with a button and textbox, and i want it so that when you click the button it performs a search on whatever's in the textbox, and displays the results in another asp page. how can i do that? :o
thanks
-
are you searching a database or a text file?
-
a database. i know how to do the code to connect to it and all that crap, i just dunno how to react to the button being clicked and displaying the results on a new page.
-
I just post the form to a new page by doing the following
<form name="form1" method="post" action="newpage.asp">
and then in newpage.asp
Code:
<HTML>
<HEAD></HEAD>
<BODY>
<%
// request the form data
searchtext=request.form("nameoftextbox")
//connect to the database, which you said you can do
//build my sql string
thesql="SELECT * FROM mytable WHERE whatiwanttosearch LIKE '%" & searchtext & "%'"
Set Rs=oConn.Execute(thesql)
//only do the following if a match has been found
if not rs.eof or not rs.bof then
rs.movefirst
do
//write out as to which record has been found
rs.movenext
loop until rs.eof
end if
%>
</BODY>
</HTML>
hope this makes sense and that everything works. any more queries don't hesitate to ask.
-
thanks, that looks like what im after. :) however, im still a bit confused about this:
<form name="form1" method="post" action="newpage.asp">
shouldn't that be for a button instead, like:
<INPUT type=button value=Search name="button1" action="page1.asp">
-
sorry, i missed out the button, but i always do the following
Code:
<form name="form1" method="post" action="newpage.asp">
<input type="submit" name="Submit" value="Submit">
</form>
This will submit the form to the page when the user clicks on the button
-
excellent, that's what i need, thanks :)