Forums
This topic is locked
Populate checkboxes with array
Posted 20 Aug 2003 17:49:38
1
has voted
20 Aug 2003 17:49:38 Jamie Ellwood posted:
Hello,I have a form with a list of checkboxes. The form is created dynamically from a database and the checkboxes are assigned to each item that is returned in the database (each item has a unique ID). I also have another database field which contains an array of numbers (eg. 1,2,33,34). How can I check the checkboxes in my dynamic form corresponding to the numbers in the array. eg. if the array is 1,2,33,34 how can boxes 1,2,33,34 be checked.
At the moment I have got as far as this:
<input <%If (CStr((rsGeneral.Fields.Item("listID".Value)) = 13) Then Response.Write("checked" : Response.Write(""%> type="checkbox" name="checkbox" value="<%=(rsGeneral.Fields.Item("listID".Value)%>">
but this only checks the box with Unique ID = 13. Ideally, I would like to say LIKE (13,14,15), but the LIKE statement does not work.
Any help would be most appreciated.
Cheers,
Jamie
Replies
Replied 25 Aug 2003 15:55:34
25 Aug 2003 15:55:34 Erik Piisila replied:
Hi Jamie:
This seems to work for me. Hope it helps.
<% 'START OF CODE NEED FOR CHECKBOXES TO WORK WITH DREAMWEAVERMX RECORDSETS
dim strClean 'CLEAN UP ACCESS SELECTED VALUES ARRAYS (A, B, C,)
strClean = marketsets.Fields.Item("cardset".Value
strClean = Replace(strclean, ", ", ","
' END OF DREAMWEAVERMX SELECTED VALUES CLEANING OF COMMA SEPARATED VALUES %>
<% ' CREATE ARRAYS OF VALUES FOR CheckBOX
While (NOT cards.EOF)
dim strType1 ' Card Values in array
strType1 = strType1 & cards.Fields.Item("awmid".Value & "," ' Card Values in array
cards.MoveNext()
Wend
If (cards.CursorType > 0) Then
cards.MoveFirst
Else
cards.Requery
End If
%>
<% ' MANIPULATE ARRAYS FROM PREVIOUS STEP TO WRITE CheckBOX WITH SELECTED VALUES FROM ACCESS DATABASE COMMA SEPARATED VALUE
strSelection = strClean '"x,y,z" '* LIST OF RECORDED USER SELECTIONS FROM ACCESS IN CLEANED ARRAY
strSelection = "," & strSelection & "," '"," & strSelection & ","
strFull = strType1'"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" COMPLETE LIST OF POSSIBLE VALUES IN CREATED ARRAY
Dim arrFull, intEntry, strSelected
arrFull = split(strFull, "," 'Values
%>
<font size="1" face="Arial, Helvetica, sans-serif">
<%
For intEntry = lBound(arrFull) To uBound(arrFull)
if instr(strSelection,"," & arrFull(intEntry) & "," > 0 then
strSelected = "checked"
else
strSelected = ""
end if
%>
<input name="cardset" type="checkbox" id="cardset" value="<%=arrFull(intEntry)%>" <%=strSelected%>>
<%=arrFull(intEntry)%>
<%
Next
%>
This seems to work for me. Hope it helps.
<% 'START OF CODE NEED FOR CHECKBOXES TO WORK WITH DREAMWEAVERMX RECORDSETS
dim strClean 'CLEAN UP ACCESS SELECTED VALUES ARRAYS (A, B, C,)
strClean = marketsets.Fields.Item("cardset".Value
strClean = Replace(strclean, ", ", ","
' END OF DREAMWEAVERMX SELECTED VALUES CLEANING OF COMMA SEPARATED VALUES %>
<% ' CREATE ARRAYS OF VALUES FOR CheckBOX
While (NOT cards.EOF)
dim strType1 ' Card Values in array
strType1 = strType1 & cards.Fields.Item("awmid".Value & "," ' Card Values in array
cards.MoveNext()
Wend
If (cards.CursorType > 0) Then
cards.MoveFirst
Else
cards.Requery
End If
%>
<% ' MANIPULATE ARRAYS FROM PREVIOUS STEP TO WRITE CheckBOX WITH SELECTED VALUES FROM ACCESS DATABASE COMMA SEPARATED VALUE
strSelection = strClean '"x,y,z" '* LIST OF RECORDED USER SELECTIONS FROM ACCESS IN CLEANED ARRAY
strSelection = "," & strSelection & "," '"," & strSelection & ","
strFull = strType1'"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" COMPLETE LIST OF POSSIBLE VALUES IN CREATED ARRAY
Dim arrFull, intEntry, strSelected
arrFull = split(strFull, "," 'Values
%>
<font size="1" face="Arial, Helvetica, sans-serif">
<%
For intEntry = lBound(arrFull) To uBound(arrFull)
if instr(strSelection,"," & arrFull(intEntry) & "," > 0 then
strSelected = "checked"
else
strSelected = ""
end if
%>
<input name="cardset" type="checkbox" id="cardset" value="<%=arrFull(intEntry)%>" <%=strSelected%>>
<%=arrFull(intEntry)%>
<%
Next
%>
Replied 25 Aug 2003 15:57:50
25 Aug 2003 15:57:50 Erik Piisila replied:
Hi Jamie:
This seems to work for me. Hope it helps.
<% 'START OF CODE NEED FOR CHECKBOXES TO WORK WITH DREAMWEAVERMX RECORDSETS
dim strClean 'CLEAN UP ACCESS SELECTED VALUES ARRAYS (A, B, C,)
strClean = marketsets.Fields.Item("cardset".Value
strClean = Replace(strclean, ", ", ","
' END OF DREAMWEAVERMX SELECTED VALUES CLEANING OF COMMA SEPARATED VALUES %>
<% ' CREATE ARRAYS OF VALUES FOR CheckBOX
While (NOT cards.EOF)
dim strType1 ' Card Values in array
strType1 = strType1 & cards.Fields.Item("awmid".Value & "," ' Card Values in array
cards.MoveNext()
Wend
If (cards.CursorType > 0) Then
cards.MoveFirst
Else
cards.Requery
End If
%>
<% ' MANIPULATE ARRAYS FROM PREVIOUS STEP TO WRITE CheckBOX WITH SELECTED VALUES FROM ACCESS DATABASE COMMA SEPARATED VALUE
strSelection = strClean '"x,y,z" '* LIST OF RECORDED USER SELECTIONS FROM ACCESS IN CLEANED ARRAY
strSelection = "," & strSelection & "," '"," & strSelection & ","
strFull = strType1'"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" COMPLETE LIST OF POSSIBLE VALUES IN CREATED ARRAY
Dim arrFull, intEntry, strSelected
arrFull = split(strFull, "," 'Values
%>
<font size="1" face="Arial, Helvetica, sans-serif">
<%
For intEntry = lBound(arrFull) To uBound(arrFull)
if instr(strSelection,"," & arrFull(intEntry) & "," > 0 then
strSelected = "checked"
else
strSelected = ""
end if
%>
<input name="cardset" type="checkbox" id="cardset" value="<%=arrFull(intEntry)%>" <%=strSelected%>>
<%=arrFull(intEntry)%>
<%
Next
%>
This seems to work for me. Hope it helps.
<% 'START OF CODE NEED FOR CHECKBOXES TO WORK WITH DREAMWEAVERMX RECORDSETS
dim strClean 'CLEAN UP ACCESS SELECTED VALUES ARRAYS (A, B, C,)
strClean = marketsets.Fields.Item("cardset".Value
strClean = Replace(strclean, ", ", ","
' END OF DREAMWEAVERMX SELECTED VALUES CLEANING OF COMMA SEPARATED VALUES %>
<% ' CREATE ARRAYS OF VALUES FOR CheckBOX
While (NOT cards.EOF)
dim strType1 ' Card Values in array
strType1 = strType1 & cards.Fields.Item("awmid".Value & "," ' Card Values in array
cards.MoveNext()
Wend
If (cards.CursorType > 0) Then
cards.MoveFirst
Else
cards.Requery
End If
%>
<% ' MANIPULATE ARRAYS FROM PREVIOUS STEP TO WRITE CheckBOX WITH SELECTED VALUES FROM ACCESS DATABASE COMMA SEPARATED VALUE
strSelection = strClean '"x,y,z" '* LIST OF RECORDED USER SELECTIONS FROM ACCESS IN CLEANED ARRAY
strSelection = "," & strSelection & "," '"," & strSelection & ","
strFull = strType1'"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z" COMPLETE LIST OF POSSIBLE VALUES IN CREATED ARRAY
Dim arrFull, intEntry, strSelected
arrFull = split(strFull, "," 'Values
%>
<font size="1" face="Arial, Helvetica, sans-serif">
<%
For intEntry = lBound(arrFull) To uBound(arrFull)
if instr(strSelection,"," & arrFull(intEntry) & "," > 0 then
strSelected = "checked"
else
strSelected = ""
end if
%>
<input name="cardset" type="checkbox" id="cardset" value="<%=arrFull(intEntry)%>" <%=strSelected%>>
<%=arrFull(intEntry)%>
<%
Next
%>
Replied 02 Sep 2003 12:04:48
02 Sep 2003 12:04:48 Jamie Ellwood replied:
Thanks for the help steelerfan70. Unfortunately, I am not ASP adept enough to use your code and edit it. I was more after a solution where someone could suggest what I replace the 13 with in my example to make the script check more boxes than just checkbox 13.
My array could contain many numbers, sospecifying a complete list of possible values would not be suitable for my application.
Any more ideas anyone <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
My array could contain many numbers, sospecifying a complete list of possible values would not be suitable for my application.
Any more ideas anyone <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
Replied 27 Dec 2006 21:10:54
27 Dec 2006 21:10:54 David Perry replied:
Hi Erik
Thank you for the code, all seems to be working well except for one small issue. I keep getting an additional checkbox at the end of the list. The checkbox is on its own with now label associated with it. For example the list may be something like this:
<checkbox> blue
<checkbox> green
<checkbox> yellow
<checkbox> red
<checkbox>
Any assistance would be appreciated.
Thank you
Thank you for the code, all seems to be working well except for one small issue. I keep getting an additional checkbox at the end of the list. The checkbox is on its own with now label associated with it. For example the list may be something like this:
<checkbox> blue
<checkbox> green
<checkbox> yellow
<checkbox> red
<checkbox>
Any assistance would be appreciated.
Thank you