Solved

How to check a checkbox if the value is TRUE?

Posted on 2011-03-16
7
641 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
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 33

Assisted Solution

by:paulmacd
paulmacd 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now