We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now


Bind data to a checkbox

Swn-Y-Mor asked
Medium Priority
Last Modified: 2012-08-13
Classic ASP, VBScript and Access database

I am creating an 'Edit Item' page, and I now want to bind ItemYesNo value to a checkbox, so that checkbox displays correct value stored in db.

Here's what I have so far....

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="<%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>

but it doesn't work. Help

I already posted this question herein Dreamweaver section, but thought here might be more suitable.
Watch Question

What do you want to do exactly ? Check the checkbox or set its value to your ItemYesNo value ? Maybe both ?

Here is if you want to do both :

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="<%=CStr(rsItem.Fields.Item("ItemYesNo").Value)%>" <%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>>


I am trying to set the Checkbox's value to the value stored in my database.

I have a list of Items at a normal price. Every now and then, I need a clearout, and put some items on sale. I want to be able to tick a checkbox to show that that item is on sale.
This I can do easily.
I now need to edit the details of some items, and have a 'Edit Details' form containing a checkbox (which should be ticked or unticked depending if on sale)
all my checkboxes are unticked each time, even though i know that some should be.

The code i provided will :
- set the value of the ItemYesNo input to your ItemYesNo current value
- check the checkbox if the value is 1

Now if by "editing" you mean that the user edit and can change the setting of the item to "on sale" or "not on sale" then you should always put 1 in the value of your input checkbox, and just do the server test to know if on edit entering the item is already on sale or not (that is if your checkbox should be check or not by default).
In any case, when the user validates the form :
- if the checkbox is checked (whether the user checked it or it was checked by default and the user did not change its state) you will have the value 1 in the ItemYesNo parameter of the QueryString (or the Form if method POST).
- If it is not checked, no ItemYesNo parameter will be passed to your validation page through QueryString (or Form)

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="1" <%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>>

Hope this help.


Tried your code, but still no joy.
Yes, by editing, I mean that my user can decide what is 'On sale' and what is 'Not on sale'

My access database field is a Yes/No datatype

Would it help if I email you the page code?

Ok send me your code. You will find my email by sneding it at my member name @ gmail.com.


OK, code sent.

Ok i will check tomorrow morning (it's 1 AM here now ;)
But first i just took a rapid look on your edit page generated source code.
The value of your DB ItemYesNo is Yes in case where it is in sale (you said it but i did not catch it ;)
So for your edit page, to show the checkbox in the good state, the input code should be :

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="Yes" <%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("Yes")) Then Response.Write("checked")%>>

Your Update code for your DB should then put "Yes" in the case where you have something in the Request.Form("ItemYesNo"). Else it should put "No" in the field.

Ok i looked at your code but i can't see what is not working, all seems to be fine.
Does the page sets the correct value to your DB ItemYesNo Field if the checkbox is checked, or not ?

I do not know well Access and the Yes/No field, and what kind of value it returns (strings "Yes"/"No", integers 1/0, booleans True/False ?).
Can you just output the value of rsItem("ItemYesNo") (before your input for example) to see what value it returns ? (just add <%=rsItem("ItemYesNo")%>)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


Value returned using <%=rsItem("ItemYesNo")%> is True

Amended your code above to give the following :-

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="True" <%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("True")) Then Response.Write("checked")%>>

And it worked.............Thank You very much!
I'll award you the points straight away
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.