Results 1 to 4 of 4

Thread: Having asp form with multiple checkboxes to query the database.

  1. #1
    Join Date
    Oct 2008
    Posts
    100

    Having asp form with multiple checkboxes to query the database.

    Hi,

    I am new to ASP programming.
    I am just wondering if I can set multiple checkboxes & then form a select query for my database to show output according to the selected checkboxes?
    I mean on a form user will just select say 7 out of 10 checkboxes & now he will click on A button "Submit" & it will fetch the appropriate column results from the database for 7 elements selected.

    I think I have made clear what I need to do?

    Broot

  2. #2
    Join Date
    May 2008
    Posts
    1,149

    Re: Having asp form with multiple checkboxes to query the database.

    Hey Can you tell us some more details about your query?
    OK You have 10 check boxes. Now if user select 6 checkboxex, do you want to show a result tah will have all the selected fields? Or any I mean its "And" or "Or". Can you please be more specific?

    Code:
    Select * from tablename WHERE tablename.fieldname =  
      
    Forms![Formname]![ComboBoxName]  
      
    or  
      
    Select * from tablename WHERE tablename.fieldname <>  
      
    Forms![Formname]![ComboBoxName]  
      
    or  
      
    Select * from tablename WHERE tablename.fieldname NOT  
      
    Forms![Formname]![ComboBoxName]

  3. #3
    Join Date
    Apr 2008
    Posts
    53

    Re: Having asp form with multiple checkboxes to query the database.

    The value of the checkboxes would be set as the id from aTable. As you can see the checkboxes are all named the same thing. This code segment is a bit more complicated. You have a table (called aTable in this example), with a primary key column named id and a bit (yes/no for access people) field called active. What you want to do is display a form with a checkbox for each record in aTable and allow the user to update the active field for every record in one submission (where active will be set to 1 if the checkbox is ticked and set to 0 if it is unticked). Obviously you could simplify things by having each record in it's own form but this would make updating large numbers of records a real pain.
    http://www.codeproject.com/KB/databa...rdatabase.aspx

    I hope this helps.

  4. #4
    Join Date
    Oct 2008
    Posts
    24

    Re: Having asp form with multiple checkboxes to query the database.

    Here is the code for multiple checkboxes & select statement:
    Page one the input
    Code:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    </HEAD>
    <title>Multiple checkbox select sample</title>
    <BODY>
    <!-- Author: Adrian Forbes -->
    <%
    strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;
    PWD=Password;DATABASE=Database_Name
    set conn = server.createobject("adodb.connection")
    conn.open strconn
    set objRS = createobject("ADODB.Recordset")
    objRS.Open "select ID, strParent, bitEnabled from Parents", strconn
    %>
    <p>
    List of all parents in database, those that are enabled are checked.
    </p>
    <form name=frmTest action="MultipleCheckboxesTarget.asp" method=POST>
    <%
    iCount = 0
    while not objRS.EOF
        lID = clng(objRS("ID"))
        iCount = iCount + 1%>
    <input type=CHECKBOX name=chkParent<%=iCount%> value="<%=objRS("ID")%>"<%if objRS("bitEnabled") then Response.Write " CHECKED" end if%>><%=objRS("strParent")%><br>
    <%    objRS.MoveNext
    wend
    objRS.Close
    set objRS.ActiveConnection = nothing
    set objRS = nothing
    %>
    <input type=HIDDEN name=txtCount value="<%=iCount%>">
    <p><input type=SUBMIT value="Select"></p>
    </form>
    </BODY>
    </HTML>
    Page 2. Shows the Results of what was selected

    Code:
    <%@ Language=VBScript %>
    <HTML>
    <HEAD>
    <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
    <title>Checkbox selection</title>
    </HEAD>
    <BODY>
    <!-- Author: Adrian Forbes -->
    <%
    iCount = Request("txtCount")
    %>
    <p>
    There were <%=iCount%> checkboxes
    </p>
    <p>
    <%
    for i = 1 to iCount
        sID = Request("chkParent" & i)
        if sID = "" then
            Response.Write "Item " & i & " was NOT checked<br>"
        else
            Response.Write "Item " & i & " was checked, it's ID is " & sID & "<br>"
        end if
    next
    %>
    </p>
    </BODY>
    </HTML>
    I hope this is what you need.

Similar Threads

  1. Interrogating database with the query in MySQL
    By Xiomar in forum Software Development
    Replies: 3
    Last Post: 21-12-2010, 05:41 AM
  2. Query for columns in oracle database
    By Gerri in forum Windows Software
    Replies: 4
    Last Post: 10-02-2010, 08:27 PM
  3. Php database query
    By garfield1 in forum Software Development
    Replies: 3
    Last Post: 05-12-2009, 01:40 PM
  4. How to write the form values in Database using C#
    By Aienstaien in forum Software Development
    Replies: 3
    Last Post: 20-08-2009, 03:36 PM
  5. SQL query to delete a row in database
    By Connect_Me in forum Software Development
    Replies: 3
    Last Post: 05-05-2009, 01:45 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,255,409.05498 seconds with 16 queries