Results 1 to 7 of 7

Thread: very easy ASP question

  1. #1
    nullus
    Guest

    Red face 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?

    thanks

  2. #2
    Hyperactive Member richy's Avatar
    Join Date
    Jan 99
    Location
    Liverpool, England
    Posts
    353
    are you searching a database or a text file?
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  3. #3
    nullus
    Guest
    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.

  4. #4
    Hyperactive Member richy's Avatar
    Join Date
    Jan 99
    Location
    Liverpool, England
    Posts
    353
    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.
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  5. #5
    nullus
    Guest
    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">

  6. #6
    Hyperactive Member richy's Avatar
    Join Date
    Jan 99
    Location
    Liverpool, England
    Posts
    353
    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
    ASP, PHP, VB, JavaScript, CSS, HTML, a little C and a little CGI.

    Richard Whitehouse.
    Join the Footie Predictions League


    "Make it idiot proof and someone will make a better idiot."

  7. #7
    nullus
    Guest
    excellent, that's what i need, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •