More Fun With Checkboxes

Results 1 to 2 of 2

Thread: More Fun With Checkboxes

  1. #1
    Join Date
    Dec 1969

    Default More Fun With Checkboxes

    This is such a commonly mentioned topic that perhaps there should be a tutorial on it. Anyway, I have a form that needs to be populated by a database. Then the user can make the neccessary changes and submit those changes. I&#039m having problems with retrieving all the checked checkboxes. What happens is only one (the first check encountered) checkbox shows as being checked on the form when the page loads even if there should be more than one checkbox checked. What am I doing wrong and how can I get the form to display all the checkboxes that are checked?<BR><BR>Here is a sample of my code:<BR><BR>Set objRec = objConnection.execute("SELECT tblUser.UserID, tblUser.Name, tblSport.SportID, tblSport.Name, tblFavSport.SportID, tblFavSport.UserID FROM tblUser, tblSport, tblFavSport WHERE tblFavSport.UserID = 1;")<BR><BR>(The above SQL statement also grabs the User and Sport names to be included in textboxes.)<BR><BR>Here is the checkbox code:<BR><BR>&#060;INPUT TYPE="checkbox" NAME="Sport" VALUE= "1" &#060;% If objRec.Fields("SportID") = 1 then Response.Write " Checked"%&#062;&#062;Baseball<BR><BR>&#060;INPUT TYPE="checkbox" NAME="Sport" VALUE= "2" &#060;% If objRec.Fields("SportID") = 2 then Response.Write " Checked"%&#062;&#062;Basketball<BR><BR>&#060;INPUT TYPE="checkbox" NAME="Sport" VALUE= "3" &#060;% If objRec.Fields("SportID") = 3 then Response.Write " Checked"%&#062;&#062;Football<BR><BR>&#060;INPUT TYPE="checkbox" NAME="Sport" VALUE= "4" &#060;% If objRec.Fields("SportID") = 4 then Response.Write " Checked"%&#062;&#062;Hockey<BR><BR>&#060;INPUT TYPE="checkbox" NAME="Sport" VALUE= "5" &#060;% If objRec.Fields("SportID") = 5 then Response.Write " Checked"%&#062;&#062;Soccer<BR><BR>Any ideas on how I can get more than one checked checkbox to display when the page loads? Thanks a bunch!<BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: More Fun With Checkboxes

    See "Many-to-many and outer joins" answer not too far below here.<BR><BR>I think it is exactly what you are doing, except that he was asking to *also* produce the set of checkboxes via the query, instead of hardcoding them as you have done. But, really, it is the same problem: You need to test *EVERY* checkbox agains *EVERY* possible answer. You are getting back more than one record, you know, if the user has chosen more than one favorite sport. Yet you never do an "objRec.MoveNext" to see that other sport, do you?<BR><BR>You *could* do yours in one query, since you hard code the list of sports to choose from (though why? why not drive it off the DB as the other poster is doing, so that to add a sport you just add it to the DB and not have to change the ASP page?). But the query for favorite sports returns so little data, that it seems easier to me to treat this one the same way. If you really don&#039t want to, ask me.<BR><BR><BR>

Posting Permissions

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