ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash




Script Output:

Some sample checkbox form elements:

A Default No-Frills Checkbox:
Checkbox With An Associated Value:
Multiple Checkboxs With The Same Name:
Checkbox Which Maintains It's State:




Let's check out our values just submitted:

FYI: Note that the above form submits back to this same page. If you haven't yet submit the form then there won't be any values in the text below since they are retrieved from the form. In this case, the values reflected are simply the defaults and are the same results you would get if you submitted the form without checking anything.

The Default No-Frills Checkbox

By default, an HTML checkbox element returns nothing if it wasn't checked and a value of "on" if it was. So by checking it's value we can determine if it was checked or not when the form was submitted. The No-Frills Checkbox was: Not Checked .

Checkbox With An Associated Value

If you don't like the fact that the checkbox returns the value of "on" it's really easy to change. Simply add a value parameter and assign to it what you'd like the value returned by the checkbox to be. The Checkbox With An Associated Value returned: .

Multiple Checkboxs With The Same Name

Probably one of the most useful uses of the checkbox is to allow users to check multiple selections. Instead of having to chech each box's status individually you can simply name them all the same and the results will be returned in a convenient collection like fashion.

You can access them in a number of ways. First you can use the "For Each" syntax illustrated here (in the source code at least): .

Along the same lines you can access them by index: .

And perhaps the easiest way is to just get them as a comma delimited list: .

Checkbox Which Maintains It's State

At this point there's really nothing different about this checkbox from any other, but I thought I should illustrate the technique when building the form (see the form generating section of the source code) because it's so useful in real life. In particular, when you're sending a user back to the form to check their entries, it's really frustrating for them if they have to re-enter all their values and re-check all the boxes.

In terms of the value, like I said, this is just like the standard checkbox, but just to keep up the pattern... Checkbox Which Maintains It's State returned: .


ASP HTML Download            FAQ

ASP.NET Version

Checkboxes are probably one of the two most confusing HTML form elements. Dealing with them via ASP isn't hard, but it can get confusing. Hopefully this will help clear things up for you.

Note that I've used "Get" for the form so that you can see the form data being transferred on the QueryString. I thought that it might help you keep track of what's actually being sent back to the server and understand the checkbox operation a little better.

Because of their similarity, if you haven't already seen it, you should probably check out our radio button sample as well.


Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES