Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 664
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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