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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
hongjunCommented:
Then in your processing page,

<%
If Request("ItemYesNo") = "Yes" Then
    ' checked
Else
   ' not checked
End If
%>
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.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

hongjunCommented:
Then ignore my http:#16353870
Swn-Y-MorAuthor Commented:
Hey Hongjun,
Don't give up on me now!
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")%>">
hongjunCommented:
Post more code.
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Dreamweaver

From novice to tech pro — start learning today.