复选框问题
表xf
id yhsm
1 20,10
<%set rsxg=server.CreateObject("adodb.recordset")
rsxg.open "select * from xf where mx='"&session("mx")&"' and id=1",conn,1,3%>
yhsm=rsxg("yhsm")
<input name="yhsm" type="checkbox" id="yhsm" value="20"
<%if instr(yhsm,"20")>0 then response.write "checked"%>>
<input name="yhsm" type="checkbox" id="yhsm" value="10" <%if instr(yhsm,"10")>0 then response.write "checked"%>>
<input name="yhsm" type="checkbox" id="yhsm" value="20" <%if instr(yhsm,"20")>0 then response.write "checked"%>>
<input name="yhsm" type="checkbox" id="yhsm" value="50" <%if instr(yhsm,"50")>0 then response.write "checked"%>>
按表xf中的数据,在修改页面中应该只勾选第1,2个复选框,但是现在确勾选了第1,2,3个复选框,因为第1个和第3个的值是一样的,请问红色部分怎样写才正确?
------解决方案--------------------yhsm="20,10" '从数据库取出值rsxg("yhsm")
yhsm=","&yhsm&","
Function check(v)
If instr(yhsm,","&v&",")>0 Then
yhsm=Replace(yhsm,","&v&",",",")
check="checked"
End If
End function
%>
<input name="yhsm" type="checkbox" value="20" <%=check("20")%>>
<input name="yhsm" type="checkbox" value="10" <%=check("10")%>>
<input name="yhsm" type="checkbox" value="20" <%=check("20")%>>
<input name="yhsm" type="checkbox" value="50" <%=check("50")%>>
======================这有问题吗?