[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

How to check a checkbox if the value is TRUE?

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
Kevin Smith
Asked:
Kevin Smith
4 Solutions
 
jkofteCommented:
you should try checked="true"
0
 
JoeNuvoCommented:
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
 
GundogTrainerCommented:

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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Paul MacDonaldDirector, Information SystemsCommented:

<input id="Checkbox1" type="checkbox"
<%
If (CStr((Recordset1.Fields.Item("forms").Value)) = CStr("TRUE")) Then
  Response.Write("checked")
End If
%>
/>
0
 
Kevin SmithAuthor Commented:
JoeNuvo, yep, returns true.
0
 
JoeNuvoCommented:
and to set checkbox value, just Response.Write(" checked ") is enough.
0
 
Kevin SmithAuthor Commented:
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

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now