Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 09-07-2009
Member
 
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
Reply With Quote
  #2  
Old 09-07-2009
Member
 
Join Date: May 2008
Posts: 1,144
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]
Reply With Quote
  #3  
Old 09-07-2009
Member
 
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.
Reply With Quote
  #4  
Old 09-07-2009
Member
 
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Having asp form with multiple checkboxes to query the database."
Thread Thread Starter Forum Replies Last Post
Interrogating database with the query in MySQL Xiomar Software Development 3 21-12-2010 05:41 AM
Query for columns in oracle database Gerri Windows Software 4 10-02-2010 08:27 PM
Php database query garfield1 Software Development 3 05-12-2009 01:40 PM
How to write the form values in Database using C# Aienstaien Software Development 3 20-08-2009 03:36 PM
SQL query to delete a row in database Connect_Me Software Development 3 05-05-2009 01:45 PM


All times are GMT +5.5. The time now is 07:47 PM.