Link to home
Start Free TrialLog in
Avatar of Swn-Y-Mor
Swn-Y-Mor

asked on

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
Avatar of hongjun
hongjun
Flag of Singapore image

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

<%
If Request("ItemYesNo") = "Yes" Then
    ' checked
Else
   ' not checked
End If
%>
Avatar of Swn-Y-Mor
Swn-Y-Mor

ASKER

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.
Then ignore my http:#16353870
Hey Hongjun,
Don't give up on me now!
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")%>">
Post more code.
ASKER CERTIFIED SOLUTION
Avatar of smaccari
smaccari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial