Solved

How to check a checkbox if the value is TRUE?

Posted on 2011-03-16
7
652 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query group by data in SQL Server - cursor? 3 64
Unexpected End of File 11 58
MS SQL + date 6 42
Update one rows based on previous row 5 30
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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