Classic Asp Submitting Multi-value Checkbox Selections And Then Displaying Choices With Other Table Items
I've looked all over the web and cannot find the answer to this riddle. I am still using VBSCRIPT (Classic ASP) and I have two tables in SQL, (Jobs and Tasks) Jobs Table ID TaskID
Solution 1:
Get the tasks in a recordset. Loop through the recordset to display the tasks and check for the ID in the Jobs.TaskID. If the value exists, show it as checked.
e.g.
sTaskID = rsQuery("TaskID") ' this will have value from jobs table, say 1,3set rsTasks = server.createobject("adodb.recordset")
ssql = "select * from tasks"
rsTasks.open ssql, <your connection>,....
dowhilenot rsTasks.EOF
if instr("," & sTaskID & ",", "," & rsTasks("ID") & ",") > 0then' Enclose the strings within commas, otherwise if the tasks selected has 10, then task ID 1 will show up as checked as well because the string 1 will be found within 10
bChecked = " checked"endif
%>
<input type="checkbox" value="<%=rsTasks("ID")%>" <%=bChecked%>><%=rsTasks("TaskName")%>
<%
rsTasks.moveNext
loopPlease note that the comma separated values may be in the form 1,3 or 1, 3 i.e. a space after comma. You'll need to modify the code accordingly to handle that.
Post a Comment for "Classic Asp Submitting Multi-value Checkbox Selections And Then Displaying Choices With Other Table Items"