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

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

Sample HTML Code generated by the ASP:
<h2>Some sample checkbox form elements:</h2>
<form action="/samples/checkbox.asp" method="get">
  A Default No-Frills Checkbox:
  <input type="checkbox" name="default" />
  <br />
  Checkbox With An Associated Value:
  <input type="checkbox" name="value_specified" value="Some Value" />
  <br />
  Multiple Checkboxs With The Same Name:
  <input type="checkbox" name="multiple" value="1" />
  <input type="checkbox" name="multiple" value="2" />
  <input type="checkbox" name="multiple" value="3" />
  <br />
  Checkbox Which Maintains It's State:
  <input type="checkbox" name="state_keeper"
  <br />
  <br />
  <input type="submit" />
<br />
<br />
<br />
<h2>Let's check out our values just submitted:</h2>
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 retreived
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.
<p><strong>The Default No-Frills Checkbox</strong></p>
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 of not when the form was submitted.
The No-Frills Checkbox was: <strong>
<p><strong>Checkbox With An Associated Value</strong></p>
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:
<strong>Some Value</strong>.
<p><strong>Multiple Checkboxs With The Same Name</strong></p>
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):
1 2 3 
Along the same lines you can access them by index:
1 2 3 
And perhaps the easiest way is to just get them
as a comma delimited list:
1, 2, 3
<p><strong>Checkbox Which Maintains It's State</strong></p>
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:


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers