Changing boolean values in a database using checkboxes.

I have a SQL2000 DB with a table about 'builders'. It has three fields: ID, Name, IsActive. IsActive is a boolean field. I  would like to display the contents of the table with check-boxes for IsActive column in a web-page. When I check or uncheck the check-boxes, the values in the DB should change after I click a submit button.

This a piece of code I used to simply display the contents:

<div align=center>
<table border=1 cellspacing=0 cellpadding=2><tr>
<td align=center><b>Builder ID</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Active?</b></td></tr>
<%
do until rs.EOF
%>
<tr>
<td><%=rs(0)%></td>
<td><%=rs(1)%></td>
<td><%=rs(4)%></td>
</tr>
<%
rs.movenext
loop
%>
</table></div>
n4narikAsked:
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.

kevp75Commented:
ok.  write another page to do the work of the update.  Then make <%=rs(4)%> a link to that page based on true/false.  On the originating page just have an if, else, then statement to make it recognize the value of rs(4) and whether the checkbox should be defaulted to checked for example:

if rs(4) = 1 then
  response.write("<input type='checkbox' name='somename' value='1' checked />")
  response.write("<input type='checkbox2' name='somename' value='0' onClick='firetheeventtoloadtheupdatepage' />")
else
  response.write("<input type='checkbox' name='somename' value='1' onClick='firetheeventtoloadtheupdatepage' />")
  response.write("<input type='checkbox2' name='somename' value='0' checked />")
end if

use some javascript on the check box to fire that same page by using the onClick event
kriyengCommented:
<div align=center>
<form action="YourUpdatePage.asp">
<table border=1 cellspacing=0 cellpadding=2><tr>
<td align=center><b>Builder ID</b></td>
<td align=center><b>Name</b></td>
<td align=center><b>Active?</b></td></tr>
<%
do until rs.EOF
%>
<tr>
<td><%=rs(0)%></td>
<td><%=rs(1)%></td>
<td><input <%If ((rs(4) = TRUE) Then Response.Write("checked") : Response.Write("")%> name="IsActive" type="checkbox" id="IsActive" value="<%=rs(0)%>" >td>
</tr>
<%
rs.movenext
loop
%>
</table>
</form></div>

When you submit the form you will receive a string named "IsActive" where you have all the buider IDs that are active separated with coma: for example:  43, 47, 58, ... , 132

If you split this string you will have all the builder IDs that have checked as "IsActive"

You can receive the builders IDs like this:

Dim B_IDs

if request.form("IsActive")<>"" then
   B_IDs=split(request.form("IsActive"),",")
   for i=0 to ubound(B_IDs)
        B_IDs(i)-->each ID Active.
   next
end if

In your update page, you could set to not active all the records and set IsActive to all received IDs.

bye!

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
n4narikAuthor Commented:
Thank you! It works! Can I give kevp75 some 100 points though?!
kevp75Commented:
:) thanks....to do that you wil have to do a split
kriyengCommented:
thanks n4narik nice to help you!
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
ASP

From novice to tech pro — start learning today.