开发者

Get recordset value to display checkbox as checked

开发者 https://www.devze.com 2023-01-16 11:34 出处:网络
I have a checkbox called \"cbBatch\" on one of my pages.When i check the box and submit the form, \"cbBatch\" is stored with a value of 1.On the next page, I need cbBatch to be \"checked\" if the valu

I have a checkbox called "cbBatch" on one of my pages. When i check the box and submit the form, "cbBatch" is stored with a value of 1. On the next page, I need cbBatch to be "checked" if the value in the corresponding database field is "1". If it's 0, then unchecked. I have attempted to write it like this:

<input type=开发者_如何学运维"checkbox" name="cbBatch<%=vIndex%>" id="cbBatch<%=vIndex%>" value="<%If RS("batch") = 1 Then Response.Write " checked" End If%>">

my database field is an integer, fyi. and this isn't working. I did a response.write to verify that the value of the checkbox is indeed 1, and it is. so i don't understand why this isn't working. What am I missing?

Thanks!


Couple of things.

The recordset doesn't return integers, unless you explicitly cast the returned value to an integer.

Secondly, to set a checkbox to checked you don't set the value to checked. You just set the "checked" property.

This should work for you:

<input type="checkbox" name="cbBatch<%=vIndex%>" id="cbBatch<%=vIndex%>"<%If "" & RS("batch") = "1" Then Response.Write " checked" End If%>>
0

精彩评论

暂无评论...
验证码 换一张
取 消