views:

28

answers:

1

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!

A: 

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%>>
Tchami
That doesn't seem to work. What happens is that I the word "checked" appears directly beside the checkbox. Bummer.
baldwingrand
Tchami
perfect. thanks!
baldwingrand