Bind data to checkbox

Classic ASP, VBScript and Access database

I am creating an 'Edit Item' page, and I now want to bind ItemYesNo value to a checkbox, so that checkbox displays correct value stored in db.

Here's what I have so far....

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="<%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>
">

but it doesn't work. Help
Swn-Y-MorAsked:
Who is Participating?
 
smaccariCommented:
Just reposting the answer made on ASP channel:

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="True" <%If (CStr(rsItem.Fields.Item("ItemYesNo").Value) = CStr("True")) Then Response.Write("checked")%>>

The db field had a value of True/False though.
0
 
hongjunCommented:
do something like this

Try this


<input name="ItemYesNo" type="checkbox" id="ItemYesNo" value="Yes" <%If CStr(rsItem("ItemYesNo")) = "1" Then Response.Write "checked"%>>



hongjun
0
 
hongjunCommented:
Then in your processing page,

<%
If Request("ItemYesNo") = "Yes" Then
    ' checked
Else
   ' not checked
End If
%>
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Swn-Y-MorAuthor Commented:
Sorry, not too sure what you mean by processing page.
I only have the one page, that has a form (using the 'post' method) and uses a standard DW Update records behaviour.
0
 
hongjunCommented:
Then ignore my http:#16353870
0
 
Swn-Y-MorAuthor Commented:
Hey Hongjun,
Don't give up on me now!
0
 
RouchieCommented:
Swn-Y-Mor, you are nearly there on your attempt.  The problem is that you are trying to set the VALUE property of the checkbox, where actually you need to set the CHECKED property based on your database value.

<input name="ItemYesNo" type="checkbox" id="ItemYesNo" checked="<%If (CStr((rsItem.Fields.Item("ItemYesNo").Value)) = CStr("1")) Then Response.Write("checked")%>">
0
 
hongjunCommented:
Post more code.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.