Hej!
har följande kod för att visa uppdrag i en listmeny. Checkboxarna begränsar urvalet genom att ändra where-villkoret.
<%
Dim objRS, objConn, strSQL, strStatus
If request("status") <> "" then
strStatus = request("status")
Else
strStatus = "0,1,2,3,4,5"
End If
Response.write "<br>" & strStatus
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "DSN=uppdragNu"
objConn.Open
strSQL = "SELECT DISTINCT * " &_
"FROM tblTask " &_
"WHERE status in (" & strStatus & ") " &_
"ORDER BY taskNr"
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open strSQL, objConn, 3, 1
%>
<form name="chooseStatus" method="post" action="chooseTask.asp">
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="67">Planerade</td>
<td width="24"><input name="status" type="checkbox" id="planned" onClick="this.form.submit();" value="0" <% If instr(request("status"), "0") <> "0" or request.form = "" then response.Write "checked" End if%>></td>
<td width="74">Utskickade</td>
<td width="25"><input name="status" type="checkbox" onClick="this.form.submit();" value="1" <% If instr(request("status"), "1") <> "0" or request.form = "" then response.Write "checked" End if%>></td>
<td width="64">Mottagna</td>
<td width="25"><input name="status" type="checkbox" onClick="this.form.submit();" value="2" <% If instr(request("status"), "2") <> "0" or request.form = "" then response.Write "checked" End if%>></td>
<td width="64">Pågående</td>
<td width="18"><input name="status" type="checkbox" onClick="this.form.submit();" value="3" <% If instr(request("status"), "3") <> "0" or request.form = "" then response.Write "checked" End if%>></td>
<td width="42">Klara</td>
<td width="15"><input name="status" type="checkbox" onClick="this.form.submit();" value="4" <% If instr(request("status"), "4") <> "0" or request.form = "" then response.Write "checked" End if%>></td>
<td width="33">Fakt</td>
<td width="49"><input name="status" type="checkbox" onClick="this.form.submit();" value="5" <% If instr(request("status"), "5") <> "0" or request.form = "" then response.Write "checked" End if%>></td>
</tr>
</table>
</Form>
<form name="chooseTaskForm" method="post" action=""><p><select name="taskList" size="10" id="TaskList">
<% Do until ObjRS.EOF %>
<option value="<% =objRS("TaskNr")%>">
<% =objRS("TaskNr") & " " & objRS("customerName") & " "%>
<%If Len(objRS("task")) > 30 then
Response.Write left(objRS("task"),27) & "..."
Else
Response.write objRS("task")
End If%>
</option>
<% objRS.Movenext %>
<% Loop %>
</select>
<%
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>
</p>
<p>
<input name="choose" type="button" id="choose" onclick="makeChoice( this );" value="Välj!">
</p>
</form>
</body>
</html>
För att alla checkboxar ska vara ifyllda och att alla poster ska visas när fönstret öppnas har jag följande kod (ingår i koden ovanför)
If request("status") <> "" then
strStatus = request("status")
Else
strStatus = "0,1,2,3,4,5"
End If
sen är tanken att man ska kunna begränsa urvalet genom att klicka bort checkboxarna. Det funferar ju fint till dess att man avmarkerat samtliga checkboxar. Då blir ju request("status") "" och alla poster visas i stället för inga. Jag fattar varför det blir så, men kan man göra på nått annat sätt???
Mvh
Henrik