Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    ASP & form check boxes

    Hello,
    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:
    option1,option2,option3,option4

    to make each one of the corresponding checkboxes checked off?

    thanks in advance for your time!
    -SiX

  • #2
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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 ("").

    Code:
    <%
    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"
      Else
        strOption(I) = ""
      End If
    Next
    %>
    
    <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)%>>
    etc...
    (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.

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    thanks any way, but this is more what i was looking for,,

    [code]
    Function FindCheckBox(CheckName)

    ListArray = split(rs("RemixContents"), ", ")
    for loopctr = 0 to ubound(ListArray)
    If ListArray(loopctr)= CheckName Then
    FindCheckBox = "checked"
    End If
    next

    End Function
    [\code]

    just a simple function:-)

  • #4
    Senior Coder Morgoth's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada Remaining Brain Cells: 6
    Posts
    1,402
    Thanks
    2
    Thanked 1 Time in 1 Post
    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.

  • #5
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    ya i use it alot of times, so it worked out great,

    thanks gaain for your time!:-)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •