Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamic checkboxes

Status
Not open for further replies.

ching0418

MIS
Mar 6, 2002
96
HK
hi friends,

i need some help.

i displayed (in table format) a list of all the departments and under each department is a list of the persons for that department.

what i did is to loop within the recordsets, and i have done that with this code:

<table width="200" border="1" align="center">
<% do while not rsDept.eof%>
<tr>
<td width="20" bgcolor="#006699"><div align="center">
<input type="checkbox" name="<%=rsDept("deptc")%>" value="<%=rsDept("deptc")%>">
</div></td>
<td width="164" bgcolor="#006699"><span class="style8"><%=rsDept("deptc")%></span></td>
</tr>
<%
Dim rsName
Dim rsName_numRows

Set rsName = Server.CreateObject("ADODB.Recordset")
rsName.ActiveConnection = MM_infosys_STRING
rsName.Source = "SELECT * FROM dbo.ACCNT where deptc = '" & rsDept("deptc") & "' ORDER BY lname,fname"
rsName.CursorType = 0
rsName.CursorLocation = 2
rsName.LockType = 1
rsName.Open()

rsName_numRows = 0

do while not rsName.eof
%>

<tr>
<td><input type="checkbox" name="<%=rsDept("deptc")%>" value="<%=rsName("login")%>"></td>
<td><span class="style6"><%=rsName("lname") & ", " & rsName("fname")%></span></td>
</tr>
<%
rsName.movenext
loop
rsName.Close()
Set rsName = Nothing
rsdept.movenext
loop%>


my problem now is to be able to check or uncheck all of the names under a department when i tick the department name. how will i do that? please help!

thanks in advance!
 
Thanks ken! That's what i'm looking for. I tried it and its working now. Thanks for your help.
 
Now i have a new problem. With the following code:

<tr>
<td width="26"><input type="checkbox" name="<%=rsDept("deptc")%>" value="<%=rsName("login")%>"></td>
<td width="276"><span class="style6"><%=rsName("lname") & ", " & rsName("fname")%></span></td>
</tr>

I named my checkboxes whatever department code it belongs, and gave them the corresponding Login as the value. Since the checkboxes are dynamic (no exact number of checkboxes will be displayed), how will i know that checkboxes are checked and then the values of the checkboxes will be inserted in a table.

My problem is how to call the dynamic checkboxes and insert the values in the database.

Thanks in advance.
 
Only the boxes that are actually checked will come across in the browser's Request.

Suppose you have 3 departments with these checkboxes:
<input type='checkbox' name='Finance' value='Tom'>
<input type='checkbox' name='Sales' value='Dick'>
<input type='checkbox' name='Construction' value='Harry'>

The only way you will get the values for Tom, Dick, and Harry is if all of the checkboxes are checked.

If only the checkboxes for Finance and Construction are checked, you won't get Dick.

The page that you submit to can check it like this:
IF (Len(Request.Form("Sales") > 0) THEN
Response.Write "Sales was selected"
ELSE
Response.Write "Sales was NOT selected"
END IF


Of course this will all fail if rsName("login") happens to contain an empty string or Null...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top