By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,661 Members | 1,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,661 IT Pros & Developers. It's quick & easy.

changing a checkbox value

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
swp
j_*****@hotmail.com (Jason Dykes) wrote in message news:<8e**************************@posting.google. com>...
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
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.