Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    search string with checkboxes

    Hi, I'm totally new to asp and need help with checkboxes. When a user searches on our site and there are multiple items, I'd like them to be able to click on the checkboxes and add multiple items to their cart, rather than have to add each item individually. I have to pass the checked items to the shopping cart.

    Here's my code so far... I know it's not much, but I have no clue where to go from here!

    Next to each item is a checkbox:

    <form name="checkbox" method="post" action="check_out.asp?sku_tag=<%=sku%>">
    <input type="checkbox" name="checkbox<%=sku%>" value="checkbox<%=sku%>">
    </form>


    Then, down below is a submit button:
    <input type="image" src="gfx/checked_addtocart1.jpg" name="Action" value="submit">
    </form>

    I assume I need some kind of "if checked" statement. Any help is MUCH appreciated!

    FWIW, this is my work-in-progress page:
    http://www.allegro-music.com/search_results2.asp
    (I'm responsible for some of the HTML and none of the ASP on this page.)

  • #2
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to give your checkboxes the same name so that if multiple are selected it creates a comma delimited string.

    You can then take this string and either split it to create an array or if using SQL you can use the IN clause to query the database*.

    * Will only work for numerical values.
    If you're quering text then you have to split the text into an array then either loop through each or construct a string.



    Code:
    <%
    If Len(Request.Form) > 0 Then
    	sku = Request.Form("sku")
    	If Not IsEmpty(sku) Then
    		sku = Split(sku, ",")
    		limit = Ubound(sku)
    		For x=0 To limit
    			clause = clause & "'" & sku(x) & "',"
    		Next
    		clause = Left(clause, Len(clause)-1)
    		
    		Response.Write "SQL = ""SELECT * FROM table WHERE sku IN (" & clause & ")"""
    	End If
    End If
    %>
    <form name="form1" method="post" action="">
      <input name="SKU" type="checkbox" id="SKU" value="AAA-001">
      <input name="SKU" type="checkbox" id="SKU" value="AAA-002">
      <input name="SKU" type="checkbox" id="SKU" value="BBB-001">
      <input type="submit" name="Submit" value="Submit">
    </form>

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you! Our skus have some text, i.e. AUM337. Does that mean I need to split it into an array?

    With that code, it is adding the first item checked into the cart; I suppose I need to add something to the shopping cart page to accept a string?

  • #4
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would depend on how the cart works.

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Hello there,

    I have the problem w/ the checkboxes searching too...

    here is the html and asp code

    <form action="result.asp" method="get">
    <input type="checkbox" name="course" value="cos101"> cos101 <br>
    <input type="checkbox" name="course" value="cos102"> cos102 <br>
    <input type="checkbox" name="course" value="cos103"> cos103 <br>
    <input type="checkbox" name="course" value="cos104"> cos104 <br>
    <input type="checkbox" name="course" value="cos105"> cos105 <br><br>
    <input type="submit">
    </form>

    asp code..(result.asp)

    ...
    sql = "SELECT * FROM table where "_
    & "And course Like '%" & Request.QueryString("course") & "%' ;"

    then will display the courses you choose for the semester from Access database
    or
    for example like this link to choose the topic, then display...
    http://www.nps.gov/applications/park...opicsearch.cfm

    Any suggestion?
    Thanks,
    webkido

  • #6
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you submit checkboxes with the same name then the values will produce a comma delimited string.

    You can then split it and construct a query.

  • #7
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is the database need to change? like cos101, cos102... use yes/no check (different field but same table)?
    or can just put all or either together etc. cos101, cos102, cos103 for spring semester; cos102, cos103, cos105 for summer semester...?

    if I split the checkbox then will be like cos101 cos102.. I understand that but didn't display the result what I want...

    Any example? I check asp101, and google search, not much help.

    I know mboxcar's search from the database, mine is through the html page, is all the same? or should I pull the checkbox value from the database(different table)?

    Thanks,
    webkido

  • #8
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mm.. after testing..

    I got the error message...

    Code:
    Microsoft VBScript runtime error '800a01a8'
    Object required: "
    /semester/cosresult.asp
    any idea?

    Thanks,
    webkido

  • #9
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    Ok, never mind.. i forgot the object... fixed.

    BUT..
    The resut frpm cosresult.asp display..

    Code:
    SELECT * FROM table WHERE course IN ('cos101')
    Sorry! Record not found!!

    ..man..
    at least display like:
    Semester Course
    -------------------
    Spring cos101, cos102
    Summer cos101, cos103

    How come No record found??

    any idea?
    webkido

    p.s. maybe I should write the new Thread too...

  • #10
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    You can use the SQL IN clause on a comma delimited string that isn't numeric which is querying a non numeric field with a minor modification.

    just change the value of the string like so

    sMyString = replace(request.form("widgets"), ",", "','")

    you have now added the single quotes to allow the search

    sSQL = "SELECT * FROM table WHERE course IN ('" & sMyString & "');"

  • #11
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    I know...
    I used/copied the Split code just like degsy's code
    It does do the result

    select * from table where course IN ('cos101', 'cos102')

    but still No record found..

    should at least show/display
    Spring: cos101, 102

    ok, here is my table from access database ( I think table needs redesign..)
    table
    Semester (text) | Course (text)
    Spring | cos101, cos102
    Summer | cos101, cos103
    Fall and winter etc...

    ......

    Any example? I can test and see how it works or post my 2 pages code here so can tell me whats wrong and database too...

    Thanks for help..
    webkido

  • #12
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    is this the result of a response.write to the screen? or is it hard coded in the sql statement with no variable? if neither is true, then do a response.write of your sql statement to the screen to ensure that that is indeed what the sql statement is.

    select * from table where course IN ('cos101', 'cos102')

  • #13
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry

    Yes, its from the response.write sql

    cause I wanna check the result page w/ sql, make sure the statement is right.

    Let me post my code...
    here is the page1.html
    Code:
    Search the course and see which semester you would like to attend:
    <form action="cosresult.asp" method="get">
    <input type="checkbox" name="course" value="cos101"> cos101
    <input type="checkbox" name="course" value="cos102"> cos102
    <input type="checkbox" name="course" value="cos103"> cos103
    <input type="checkbox" name="course" value="cos104"> cos104
    <input type="checkbox" name="course" value="cos105"> cos105
    <input type="checkbox" name="course" value="cos106"> cos106
    <input type="checkbox" name="course" value="cos107"> cos107
    <br><br>
    <input type="submit">
    </form>
    here is cosresult.asp...
    Code:
    <%
    Dim objConn
      Set objConn = Server.CreateObject("ADODB.Connection")
       objConn.Open "cossearch"
    %>
    You search for Course: <%= Request.QueryString("course") %>
    
    <br><br>
    
    <%
    dim scourse, myRS, sql
    
    If Len(Request.QueryString) > 0 Then
    	scourse = Request.QueryString("course")
    	If Not IsEmpty(scourse) Then
    		scourse = Split(scourse, ",")
    		Item = Ubound(scourse)
    		For x=0 To Item
    			xcos = xcos & "'" & scourse(x) & "',"
    		Next
    		xcos = Left(xcos, Len(xcos)-1)    
    
    
    sql = "SELECT * FROM table where course IN (" & xcos & ")"
     
    
    Set myRS = Server.CreateObject ("ADODB.Recordset")
    
    myRS.Open sql, objConn
    
    response.write sql & "<p>"
    'response.end
    
    If myRS.EOF then
    response.write "<font color='red'>Sorry! No Record Found!!</font>"
    Else
    
    %>
    
    <table border="1">
    <tr>
    <td bgcolor="#009966" valign="middle" align="left"><font color="#ffffff"><b>Semester</b></td>
    <td bgcolor="#009966" valign="middle" align="left"><font color="#ffffff"><b>Course</b></td>
    </tr>
    
    <%While Not myRS.EOF %>
    	<tr>
    	<td><%= myRS("semester") %> &nbsp;</td>
    	<td><%=myRS("course")%> &nbsp;</td>
                     </tr>
    <%
    	myRS.MoveNext
    	Wend
    %>
      </table>
    <%
    
         End If   'end of checkbox not empty
       End If     'end of request.querystring >0 
      myRS.Close
      Set myRS = Nothing
      objConn.Close
      Set objConn = Nothing
    End If
    
    %>
    Is this make sense? or my database table is wrong...
    The result is: No Record Found!

    If the sql statement for search I used/tried:
    Code:
    dim scourse
        scourse = Request.QueryString("course")
     
    Dim myRS, sql
    
    sql = "SELECT * FROM table where "_
            & "And course Like '%" & scourse & "%' ;"
    will do the search but only display the ones I chosen...
    like if I choose: cos101, cos102
    then display:
    Spring cos101, cos102

    how about Summer cos101, cos103 ? -- no display, but I want it display too.

    If I choose cos101, cos103
    then NO record found!
    Sould it display like:
    Spring cos101, cos102
    Summer cos102, cos103

    How come No record found??

    Is there any example or website I can look at? or Is my code bad?

    Thanks,
    webkido
    Last edited by webkido; 05-11-2006 at 09:06 PM.

  • #14
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    and if you open your access database and run that same query does it return any results? I am betting not.

    The query IN is looking for each value from the array to be the value in the course column. But you do not have that as the value you have the following as values :
    cos101, cos102
    cos102, cos103


    the string "cos101" is not the same as this string "cos101, cos102"
    That is why your LIKE query worked.
    using the IN query says to look to see if the string "cos101" is the same as this string "cos101, cos102" or this string "cos102, cos103"
    plus to check if the string "cos102" is the same as this string "cos101,cos102" or this string "cos102, cos103"

    what does the database consist of for tables? is the value cos101 a pointer to another table? out of curiosity is this a table for a course catalog similar to something a school might have? if so I have a better solution for you.

  • #15
    New Coder
    Join Date
    May 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    yes.. something like that....

    the cos101, cos102, cos103.. should point out Other table but I put them all together thought would be easier for searching... guess not!
    and stuck!! no matter what I serached from Google or all the asp forums, no answer what I want.. I only fount some website but they used code fusion...
    well.. see this website:
    http://www.nps.gov/applications/park...opicsearch.cfm
    click the checkboxes then will see the result... I am wondering if I can do something like that.. but ohh well again.. my search only searched ONE, or stick together not seperate the results I want.. like array{1,2,3,4,5} can find 1 or 2 or 3 or 4 or 5, but can't find {1, 3} but can find {1,2} or {2,3}.. etc.

    so far I only tried checkboxes.... if you have the example that would be great, I will give you my email. But I do wannt Find Why ... drive me crazy but still alive

    and yes, maybe my database got the major problem and you were right.. the database query not found any either maybe should break the table would be easier?

    Thanks again,
    webkido


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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