changing a checkbox value

J

Jason Dykes

I have a page that is database driven. The pages shows a user's name
and whether they have access to our site or not. this is done by
displaying two checkboxes positioned to the right of the users name.
The first checkbox is to deny the user access and is named something
like chkD followed by the user's id number from the database (ie;
chkD20). The second checkbox is to allow the user access and is named
chkA followed by the user's id number again (ie; chkA20). My question
is how do I get only one checkbox checked at a time for each user. In
other words, when the Allow checkbox(chkA20) is clicked, how do I
uncheck the Deny checkbox(chkD20) and vice versa? Source code follows
for possibly a better understanding of my situation. It is in
VBScript.

Do Until rs.EOF
Response.Write"<TR>" & vbcrlf
Response.Write"<TD width='50%'>&nbsp;&nbsp;&nbsp;" & rs(3) & ", " &
rs(1) & " " & rs(2) & "</TD>" & vbcrlf
Response.Write"<TD width='25%' align='center'><INPUT type='checkbox'
name='chkD" & rs(0) & "'"
if not rs(4) then response.write " checked "
response.write"></center></TD>" & vbcrlf
Response.Write"<TD width='25%' align='center'><INPUT type='checkbox'
name='chkA" & rs(0) & "'"
if rs(4) then response.write " checked "
response.write"></center></TD>" & vbcrlf
Response.Write" </TR>" & vbcrlf
rs.MoveNext
Loop

Thank you,
Jason
 
S

swp

I have a page that is database driven. The pages shows a user's name
and whether they have access to our site or not. this is done by
displaying two checkboxes positioned to the right of the users name.
The first checkbox is to deny the user access and is named something
like chkD followed by the user's id number from the database (ie;
chkD20). The second checkbox is to allow the user access and is named
chkA followed by the user's id number again (ie; chkA20). My question
is how do I get only one checkbox checked at a time for each user. In
other words, when the Allow checkbox(chkA20) is clicked, how do I
uncheck the Deny checkbox(chkD20) and vice versa? Source code follows
for possibly a better understanding of my situation. It is in
VBScript.

Do Until rs.EOF
Response.Write"<TR>" & vbcrlf
Response.Write"<TD width='50%'>&nbsp;&nbsp;&nbsp;" & rs(3) & ", " &
rs(1) & " " & rs(2) & "</TD>" & vbcrlf
Response.Write"<TD width='25%' align='center'><INPUT type='checkbox'
name='chkD" & rs(0) & "'"
if not rs(4) then response.write " checked "
response.write"></center></TD>" & vbcrlf
Response.Write"<TD width='25%' align='center'><INPUT type='checkbox'
name='chkA" & rs(0) & "'"
if rs(4) then response.write " checked "
response.write"></center></TD>" & vbcrlf
Response.Write" </TR>" & vbcrlf
rs.MoveNext
Loop

Thank you,
Jason

for each input element you create, which should be done procedurally
for consistancy and clarity if nothing else, you should add an
onchange event to change the value of it's counterpart. do the table
procedurally as well.

please keep in mind that this makes absolutely no use of CSS, which is
preferable.

try something like this: (beware line wrapping and typos...)
sub wr(x)
response.write x
end sub

' rn == record number
' dv == default value
' oc == what to do on change of the value
sub makeCheckbox(rn, dv, oc)
wr " <input type=checkbox name='" & rn & "' " & dv & "
onchange='" & oc & "'>"
end sub

' cn == cell name
sub startCell(cn, width, align)
wr " <td id='" & cn & "' width='" & width & "' align='" & align &
"'>" & vbcrlf
end sub

sub endCell()
we " </td>" & vbcrlf
end sub

' rn == row name
sub startRow(rn)
wr " <tr id='" & rn & "'>" & vbcrlf
end sub

sub endRow()
wr " </tr>" & vbcrlf
end sub

dim dv
while not rs.eof
dv = ""
startRow "A"
startCell "A1", "50%", "left"
wr "&nbsp;&nbsp;&nbsp;" & rs(3) & ", " & rs(1) & " " & rs(2)
endCell
startCell "A2", "25%", "center"
if (not rs(4)) then dv = "checked"
makeCheckbox "chkD"&cstr(rs(0)), dv, "if (this.checked==1)
{document.forms[0].chkA"&cstr(rs(0))&".checked=0; } else
{document.forms[0].chkA"&cstr(rs(0))&".checked=1;}"
endCell
startCell "A3", "25%", "center"
if (rs(4)) then dv = "checked"
makeCheckbox "chkA"&cstr(rs(0)), dv, "if (this.checked==1)
{document.forms[0].chkD"&cstr(rs(0))&".checked=0; } else
{document.forms[0].chkD"&cstr(rs(0))&".checked=1;}"
endRow
rs.movenext
wend

hth,
swp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top