4 Replies Latest reply on Jul 11, 2009 11:31 AM by MacWiz1220

    Set Checkbox State

    MacWiz1220 Level 1

      OK. I need help please. My setup is so:

      I have 3 SQL tables, a students table, with a column for either of their 8 classes, and a username column. the username is how i track users and the classes column is filled with the Class_ID when the user is added to the class.  My second table is the Classes table. it contains a class_id column and a period column (there are  8 periods in the day, A1-A4, B1-B4). My third table is the teachers table that stores the Teacher_Username as well as a column for each of their periods, populated with the appropriate class_id


      To add a student to a class, the Class_ID is placed into that students row in their appropriate period.


      I need to add users, but I can't figure out the checkboxes (I manually added some test users). The page lists all students and a check box next to the user to change their class membership. the form page before it sets the current period and teacher_username.


      I have queries to get the correct class_id by teacher_username and period from the teachers table, as well as to get the student username and period to be added to.


      What I need is if the user is in the class, the box is already checked. If they are not in the class, the box is unchecked, each student has a checkbox... Can anyone help me on this? Would my current code help? (NOTE: A user is in the class when their period column value equals that of the Class_ID for that class).


      Thanks so much!

        • 1. Re: Set Checkbox State

          Please see the sample code snippent for users first name displayed with check box dynamicaly. you can solve your problem with this  .. Hope this helps.
          UI part
          when loading.
          <cfloop query="qry_users">
          <cfif not IsDefined("user_#qry_users.UserID#")><cfset "user_#qry_users.UserID#" = 0><cfelse><cfset "user_#qry_users.UserID#" = 1></cfif>



          Design area
          <cfloop query="qry_users">
          <input type="checkbox" name="user_#qry_users.UserID#" value="1" <cfif Evaluate("user_#qry_users.UserID#") is 1> checked</cfif>>



          • 2. Re: Set Checkbox State
            MacWiz1220 Level 1

            Thanks, but I'm not sure how that helps. I doesn't take into account whether the users Period column value is equal to the value of the Class_ID I am editing (as set via the form on the previous page...). If the user period column matches the Class_ID i am editing, teh user is in the class, otherwise, they're not...


            Thanks for the help!


            Would you like to see my code so far? Maybe it will help...

            • 3. Re: Set Checkbox State
              PRABEESH_IN Level 1

              so this means i am not clear about the request. The descriptions about the logic is ok. Please specify what you want to resolve.

              Yes, provide code, that will help.

              • 4. Re: Set Checkbox State
                MacWiz1220 Level 1

                I posted this on two forums, and got an answer on the other one, but thanks anyways. I ended up using an array...