473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,406 developers and data experts.

Dealing with checkboxes

markrawlingson
346 Expert 100+
It seems that a lot of people run into this issue in regards to dealing with the result that checkboxes return to the Request.Form object. So this article is intended to fully explain how checkboxes are interpretted, what their values are and aren't, and how they should be handled if inserted into your database as a yes/no or bit field.

Most commonly, I see people trying to check a checkbox to see if it has a True or False value. This is incorrect. Checkboxes do not return a boolean value. They return, by default, a value of "on" if they are checked, and do not return a value if they are not checked. If you set the value attribute of a checkbox, the checkbox will return that value if it is checked instead of "on", but it still will not return a value if it is not checked.

Example:
Expand|Select|Wrap|Line Numbers
  1. <input type="checkbox" name="mycheckbox" id="mycheckbox"/>
  2. <!--Will return a value of "on" if it is checked, and will return EMPTY or "" if it is not checked -->
  3.  
  4. <input type="checkbox" name="mycheckbox" id="mycheckbox" value="MyNameIsMark"/>
  5. <!--Will return a value of "MyNameIsMark" if it is checked, and will return EMPTY or "" if it is not checked.-->
  6.  
Expand|Select|Wrap|Line Numbers
  1. If Request.Form("mycheckbox") = "MyNameIsMark" Then
  2.    Response.Write "My Check Box has been checked!"
  3. Else
  4.    Response.Write "No one wants to check my checkbox :("
  5. End If
  6.  
Inserting the checkbox into your database

Many people also incorrectly update their database. Especially when it comes to access.

If you are using access, a yes/no field should be supplied a value of -1 for yes, and 0 for no.

If you are using SQL Server, a bit field should be supplied a value of True or False, respectively.

I would recommend setting the default value of your yes/no or bit fields with 0 (access) or False (SQL Server). If you do this, you will not have to worry about setting the value of your bit or yes/no field to false in your script everytime you insert. Unless you specifically tell your database to set the value of your yes/no or bit field to Yes/True/-1 etc - it will automatically set itself to No/False/0 etc when a new record is inserted.

Expand|Select|Wrap|Line Numbers
  1. 'Access
  2. If Request.Form("Checkbox") = "on" Then
  3.    rs("Yes-No") = -1
  4. End If
  5.  
  6. 'SQL Server
  7. If Request.Form("Checkbox") = "on" Then
  8.   rs("Yes-No") = True
  9. End If
  10.  
Mark
Oct 26 '07 #1
0 8278

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Pete | last post by:
There is a Summary/Example further down... On page one of my site I have a form with some checkboxes and detailed descriptions. When the form is submitted (to page two), the values of the...
6
by: Timo | last post by:
I have this list of checkboxes displaying properly in Opera and IE, but cannot get it in Firefox. For some reason, in FF, the checkboxes creep farther and farther to the right across the page,...
5
by: VbUser25 | last post by:
hi i need urgent responses.. i have some 15 checkboxex on a form... i want to 1st check the no. of checkboxes that are checked?? and then loop it that many times adn insert the quantities the...
6
by: terence.parker | last post by:
I currently have the following JS in my header: function checkall(thestate) { var checkboxes=eval("document.forms.EssayList.file_id") for (i=0;i<checkboxes.length;i++)...
2
by: suzy | last post by:
hi, i have created some checkboxes at runtime via a datalist control. what code do i have to put on the server to determine which checkboxes have been clicked? any examples? thanks
10
by: rn5a | last post by:
All the rows in a DataGrid, including the Header, are accompanied with a CheckBox. I want that when the CheckBox in the Header is checked, then all the CheckBoxes should automatically get checked....
5
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
8
by: PeteOlcott | last post by:
http://archive.dojotoolkit.org/nightly/dojotoolkit/dojox/grid/tests/test_change_structure.html I would like to completely understand how GUI controls such as this one are constructed. In the...
14
by: zufie | last post by:
I have to create a QA report regarding callers calling into a phone hotline. The report consists of many checkboxes such as: Did the IBCCP agency contact you? Yes/NO How many days passed...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.