[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 326
  • Last Modified:

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>
0
n4narik
Asked:
n4narik
  • 2
  • 2
2 Solutions
 
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
0
 
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!

0
 
n4narikAuthor Commented:
Thank you! It works! Can I give kevp75 some 100 points though?!
0
 
kevp75Commented:
:) thanks....to do that you wil have to do a split
0
 
kriyengCommented:
thanks n4narik nice to help you!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now