Solved

How to check a checkbox if the value is TRUE?

Posted on 2011-03-16
7
660 Views
Last Modified: 2012-06-27
I have and asp update page with a form.  All the fields are fine, but none of the checkboxes return checked even if they are TRUE (bit) in the db.  Below is my code to check the box if TRUE (and yes, I have tried 1 as well):

<input <%If (CStr((Recordset1.Fields.Item("forms").Value)) = CStr("TRUE")) Then Response.Write("checked=""checked""") : Response.Write("")%> type="checkbox" name="forms" value="1" />

How do I have the checkboxes checked if they are true in the db?
0
Comment
Question by:Kevin Smith
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 9

Assisted Solution

by:jkofte
jkofte earned 25 total points
ID: 35147644
you should try checked="true"
0
 
LVL 11

Accepted Solution

by:
JoeNuvo earned 175 total points
ID: 35147648
print out value of CStr((Recordset1.Fields.Item("forms").Value)) to check first.
to see what is it look like for both True/False

Since value of boolean on ASP is vary, some become 0/1, or 0/-1,  or True/False  or Yes/No
You need to code it accordingly when read it from database.
0
 
LVL 8

Assisted Solution

by:GundogTrainer
GundogTrainer earned 150 total points
ID: 35147667

I have broken it up to make it more readable:

<input type="checkbox"
<%
If (CStr((Recordset1.Fields.Item("forms").Value)) = CStr("TRUE")) Then Response.Write("checked=""yes""")
%>
  name="forms"  />
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 34

Assisted Solution

by:Paul MacDonald
Paul MacDonald earned 150 total points
ID: 35147682

<input id="Checkbox1" type="checkbox"
<%
If (CStr((Recordset1.Fields.Item("forms").Value)) = CStr("TRUE")) Then
  Response.Write("checked")
End If
%>
/>
0
 

Author Comment

by:Kevin Smith
ID: 35147770
JoeNuvo, yep, returns true.
0
 
LVL 11

Expert Comment

by:JoeNuvo
ID: 35147777
and to set checkbox value, just Response.Write(" checked ") is enough.
0
 

Author Comment

by:Kevin Smith
ID: 35147875
not sure what happend...maybe I was holding my head wrong, but it's working and I did nothing.  Oh well, morning sucks.  Points to all.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question