View Full Version : ASP & form check boxes
08-15-2004, 04:53 PM
I'm using check boxes on a forum i have,
the user can select up to 8 check boxes,
when submitted to the db, the come out like:
option1,option2,option3,option4,,,and so on.
now i want users to be able to edit the same form data,
so when i pull the info from the data base to populate
the form i want to same checkboxes checked that are in the database
so how do i pull apart this info:
to make each one of the corresponding checkboxes checked off?
thanks in advance for your time!
08-15-2004, 09:54 PM
This is very simple. The checkbox is a boolean, checked = true, and unchecked = false.
When you save it to a database you will save option1, option2, option3, option4, etc.. in fields that have the datatypes set to boolean.
The way to get the information from the database to the form is by using an if statement. That is the only way I found it to work, and the reason for that is because you need to tell the box if it is True ("Checked") or False ("").
Dim SQL, oRS, I, strOption(8)
SQL = "SELECT fldOption1, fldOption2, fldOption3, fldOption4, fldOption5, fldOption6, fldOption7, fldOption8 FROM tblForm WHERE ID = " & SelectedID
Set oRS = oConn.Execute(sSQL)
For I = 1 To 8
If oRS("fldOption" & I) = True Then
strOption(I) = " checked"
strOption(I) = ""
<input name="option1" type="checkbox"<%=strOption(1)%>>
<input name="option2" type="checkbox"<%=strOption(2)%>>
<input name="option3" type="checkbox"<%=strOption(3)%>>
<input name="option4" type="checkbox"<%=strOption(4)%>>
(or "SELECT * FROM...")
Does this make sence?
When a you have <input type="checkbox" checked> it will check itself in HTML, just incase you didn't know.
08-15-2004, 11:20 PM
thanks any way, but this is more what i was looking for,,
ListArray = split(rs("RemixContents"), ", ")
for loopctr = 0 to ubound(ListArray)
If ListArray(loopctr)= CheckName Then
FindCheckBox = "checked"
just a simple function:-)
08-15-2004, 11:57 PM
Oh, ok, so the option1,option2,option3,option4 are in a string, and you just wanted to seperate?
From what you asked in your first post, I beleive my code would have done what you wanted, except that I didn't notice the options were stuck in a string or something...
That function looks like it would work, but unless you are using it more than once in other places of code, or on other pages, making it a function would be pointless.
08-16-2004, 12:14 AM
ya i use it alot of times, so it worked out great,
thanks gaain for your time!:-)