Multiple checkbox select with all values sampleHere is the code for this Example <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> </HEAD> <title>Multiple checkbox select with all values sample</title> <BODY> <!-- Author: Adrian Forbes --> <% strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name set conn = server.createobject("adodb.connection") conn.open strconn set objRS = createobject("ADODB.Recordset") objRS.Open "select ID, strParent, bitEnabled from Parents", strconn %> <p> List of all parents in database, those that are enabled are checked. </p> <form name=frmTest action="MultipleCheckboxesAllValuesTarget.asp" method=POST> <% iCount = 0 while not objRS.EOF lID = clng(objRS("ID")) iCount = iCount + 1%> <input type=HIDDEN name=txtParentID<%=iCount%> value="<%=objRS("ID")%>"> <input type=CHECKBOX name=chkParent<%=iCount%> value="<%=objRS("ID")%>"<%if objRS("bitEnabled") then Response.Write " CHECKED" end if%>><%=objRS("strParent")%><br> <% objRS.MoveNext wend objRS.Close set objRS.ActiveConnection = nothing set objRS = nothing %> <input type=HIDDEN name=txtCount value="<%=iCount%>"> <p><input type=SUBMIT value="Select" id=SUBMIT1 name=SUBMIT1></p> </form> </BODY> </HTML> Page 2 the Results page <%@ Language=VBScript %> <HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0"> <title>Checkbox selection</title> </HEAD> <BODY> <!-- Author: Adrian Forbes --> <% iCount = Request("txtCount") %> <p> There were <%=iCount%> checkboxes </p> <p> <% for i = 1 to iCount sID = Request("txtParentID" & i) if Request("chkParent" & i) = "" then Response.Write "Item " & i & " with ID of " & sID & " was NOT checked<br>" else Response.Write "Item " & i & " with ID of " & sID & " was checked<br>" end if next %> </p>
</BODY> </HTML> |