jarv
02-16-2010, 04:54 PM
writing a ForEach function to check if a checkbox is checked or not?
a friend gave me this psuedo code but I don't really understand it and which bits to change:
Function IsCategoryInRS(byVal id, ByRef formData)
... for each categoryitem in formData ...
if id == categoryitem. id
IsCategoryInRs = true
...next
End Function
sqlRs = SELECT * FROM Categories where blah = blah
while not sqlRs.EOF
if(IsCategoryInRS(sqlRS("id"), formData) then
exec UPDATE
else
exec INSERT
sqlRs.MoveNext
wend
here is my code that shows the checkboxes
Dim rsCategories1
Set rsCategories1 = Server.CreateObject("ADODB.Recordset")
rsCategories1.ActiveConnection = MM_CON_Database_STRING
rsCategories1.Source = "SELECT tblCategories.ID, tblCategories.CName, (select tblProductCategories.productID from tblProductCategories where tblProductCategories.productID=" & ID & " and tblProductCategories.categoryID=tblCategories.ID) AS pid FROM tblCategories ORDER BY tblCategories.DisplayOrder"
rsCategories1.Open()
%>
<% while NOT rsCategories1.EOF %>
<form>
<input type="checkbox" value="<%=rsCategories1("ID")%>" id="Col_Category" name="Col_Category" style="width:32px;align:left;"
<% if NOT adding then response.write(iif(rsCategories1("pid") <> "","checked",""))%> />
<%=rsCategories1("CName")%><br/>
<%
rsCategories1.movenext
wend
%>
<input type="submit" name="Operation" value="Update">
</form>
a friend gave me this psuedo code but I don't really understand it and which bits to change:
Function IsCategoryInRS(byVal id, ByRef formData)
... for each categoryitem in formData ...
if id == categoryitem. id
IsCategoryInRs = true
...next
End Function
sqlRs = SELECT * FROM Categories where blah = blah
while not sqlRs.EOF
if(IsCategoryInRS(sqlRS("id"), formData) then
exec UPDATE
else
exec INSERT
sqlRs.MoveNext
wend
here is my code that shows the checkboxes
Dim rsCategories1
Set rsCategories1 = Server.CreateObject("ADODB.Recordset")
rsCategories1.ActiveConnection = MM_CON_Database_STRING
rsCategories1.Source = "SELECT tblCategories.ID, tblCategories.CName, (select tblProductCategories.productID from tblProductCategories where tblProductCategories.productID=" & ID & " and tblProductCategories.categoryID=tblCategories.ID) AS pid FROM tblCategories ORDER BY tblCategories.DisplayOrder"
rsCategories1.Open()
%>
<% while NOT rsCategories1.EOF %>
<form>
<input type="checkbox" value="<%=rsCategories1("ID")%>" id="Col_Category" name="Col_Category" style="width:32px;align:left;"
<% if NOT adding then response.write(iif(rsCategories1("pid") <> "","checked",""))%> />
<%=rsCategories1("CName")%><br/>
<%
rsCategories1.movenext
wend
%>
<input type="submit" name="Operation" value="Update">
</form>