PDA

View Full Version : checkbox problems


dawilis
08-11-2003, 02:20 PM
I want to get the value from the db stored as a 0 or 1 ( I can do this) then on the page check the checkbox if its equel to 1 or uncheck if its a 0.

this is what I have
<input type="checkbox" value="<% =(RSQS("Alerts"))%>">
but nothing displays
help

raf
08-11-2003, 03:01 PM
a checkbox doesn't have a value atribute (AFAIK).
you need checked (i think. With radiobuttons, it's 'selected')

response.write("<input type=""checkbox""")
if RSQS.Fields("Alerts") = 1 then
response.write(" checked")
end if
response.write(">")

arnyinc
08-11-2003, 03:08 PM
If you don't specify a value for a checkbox, it will return:

"ON" - if the checkbox is checked
"" - if the checkbox isn't checked.

If you do specify a value (i.e. value="blah") it will return:

"blah" - if the checkbox is checked
"" - if the checkbox isn't checked.

raf
08-11-2003, 03:37 PM
Indeed. I was confusing with the textarea or something like that. (heatwave overhere :o )
So then it goes

response.write("<input type=""checkbox"" name=""whatever"" value=""" & RSQS.Fields("Alerts") & """")
if RSQS.Fields("Alerts") = 1 then
response.write(" checked")
end if
response.write(">")


So the checkbox is checked when the pages loads, and if it's still checked when the form is posted, request.form("whatever") will return "1"

whammy
08-12-2003, 01:22 AM
I actually have a simple but handy little function for this (XHTML compatible)...

Function IsChecked(val1,val2)
If val1 = val2 Then IsChecked = " checked=""checked"""
End Function

You'd use it like:

<%
Dim blah
blah = Request.Form("blah") 'or, obviously, rs("blah") from a recordset or whatnot
%>

<input type="checkbox" name="blah" value="X"<% = IsChecked(blah,"X") %> />


As you can probably guess, this definitely saves some space/time when creating a form with many checkboxes.

dawilis
08-14-2003, 12:53 AM
THanks all thats great work