Shows a number of checkboxes. Submitting the form shows the VALUEs of the boxes that were checked.

Contributed by
Rating: 4 stars4 stars4 stars4 stars4 stars / 11
February 01, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

Multiple checkbox select sample

Select a bunch of the checkbox's and then click submit

List of all parents in database, those that are enabled are checked.

BMW
Chevy
Ford
GMC
Mustang
Truck
Family
Van
Semi

Here is the code for this Example

Page one the input

<%@ 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

<%@ 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>

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials