7 Replies Latest reply on Apr 16, 2007 8:56 PM by Newsgroup_User

    Populating dynamic checkboxes

    WadeHammer
      I'm hung up on figuring out how to populate the checkbox on an update. What I have is a list of extras that are applied to a workorder with a foreign key tied to the ID of the extra. What I am trying to figure out is how to check the box if it's in the foreign key DB column of the workorder for updating. The first query works great on the initial INSERT and the second query would only display the original extras. Is there some way to combine them or use a ListContains statement?

      <cfquery name="ExtrasUpdate" datasource="#DataSource#" username="#dbUserName#" password="#dbPass#">
      SELECT ID, Name, Price FROM HVAC_extras WHERE ID IN (#SESSION.HVAC.ExtrasID#)
      </cfquery>

      <cfquery name="Extras" datasource="#DataSource#" username="#dbUserName#" password="#dbPass#">
      SELECT * FROM HVAC_extras
      ORDER BY ID
      </cfquery>

      <cfoutput query="Extras">
      <table width="98%" border="0" cellspacing="2" cellpadding="2">
      <tr>
      <td width="9%">
      <cfinput type="checkbox" name="Extras" value="#Extras.ID#" checked="no">
      </td>
      <td width="91%"><a href="/WorkOrders/data/extras.cfm?ID=#Extras.ID#" target="_blank">#Extras.Name#</a>
      - #DollarFormat(Extras.Price )#</td>
      </tr>
      </table>
      </cfoutput>

      Thanks for any help.
      Hope this makes sense!
        • 1. Re: Populating dynamic checkboxes
          Dan Bracuk Level 5
          Don't use cfinput for a checkbox. Use input instead. Using cfinput adds nothing useful and prevents you from doing this sort of thing.

          <input <cfif some_condition_is_met>checked="checked">>
          • 2. Populating dynamic checkboxes
            BKBK Adobe Community Professional & MVP
            I don't understand what the link is doing in the form. Couldn't you just put the data as values in form fields or hidden fields, and then submit to extras.cfm?

            > The first query works great on the initial INSERT and the second query
            > would only display the original extras.

            Aparently only data that corresponds to IDs in SESSION.HVAC.ExtrasID has been updated. It suggests there are 2 sets of IDs, those whose data is updated and those whose data is not. I would look into that. How do the insert/update queries look like?

            • 3. Re: Populating dynamic checkboxes
              WadeHammer Level 1
              Thanks for the help! Eliminating the cfinput got rid of some errors for me! BKBK, the form I submit is a different address, the links allow the customer to view the description of the extras before submitting the form. The following code works great with one "extras" value for example an ID of 4 returns the correctly checked box but when I have multiple values like 1,2,3 I don't know how to break them out seperately similar to an SQL IN query ie. SELECT ID FROM SomeTable WHERE ID IN (#Extras.ID#).

              <cfoutput query="Extras">
              <table width="98%" border="0" cellspacing="2" cellpadding="2">
              <tr>
              <td width="9%">
              <input type="checkbox" name="Extras" value="#Extras.ID#" <cfif Extras.ID EQ SESSION.HVAC.ExtrasID>checked</cfif>>
              </td>
              <td width="91%"><a href="/WorkOrders/data/extras.cfm?ID=#Extras.ID#" target="_blank">#Extras.Name#</a>
              - #DollarFormat(Extras.Price )#</td>
              </tr>
              </table>
              </cfoutput>
              Thanks again for your help!
              • 4. Re: Populating dynamic checkboxes
                BKBK Adobe Community Professional & MVP
                > the form I submit is a different address, the links allow the customer to
                > view the description of the extras before submitting the form.

                OK.

                > for example an ID of 4 returns the correctly checked box but when I have
                > multiple values like 1,2,3 I don't know how to break them out seperately
                > similar to an SQL IN query

                I think you already have that functionality. Suppose there are two or more checkboxes with the same name, extras. If they are checked and submitted, form.extras will be a comma delimited list of their respective values. Run the test. Is that what you meant?

                • 5. Re: Populating dynamic checkboxes
                  Level 7
                  you CAN use <cfinput type="checkbox"> and still achieve what you want:

                  Aside1: if you already have the id's of extras for the workorder
                  in question stored in SESSION.HVAC.ExtrasID (presumably as a
                  comma-delimited list), then you do not need your ExtrasUpdate query at all.

                  Aside2: instead of outputting a whole table for each Extra, why
                  don't you move the <cfoutput query="Extras"> INSIDE the <table></table>,
                  so you output separate rows for each extra inside same one table?

                  try this:

                  <cfquery name="Extras" datasource="#DataSource#" username="#dbUserName#"
                  password="#dbPass#">
                  SELECT * FROM HVAC_extras ORDER BY ID;
                  </cfquery>

                  <table width="98%" border="0" cellspacing="2" cellpadding="2">
                  <cfoutput query="Extras">
                  <tr>
                  <td width="9%">
                  <cfif listfind(session.hvac.extrasid, Extras.ID)>
                  <cfinput type="checkbox" name="Extras" value="#Extras.ID#" checked="yes">
                  <cfelse>
                  <cfinput type="checkbox" name="Extras" value="#Extras.ID#" checked="no">
                  <cfif>
                  </td>
                  <td width="91%"><a href="/WorkOrders/data/extras.cfm?ID=#Extras.ID#"
                  target="_blank">#Extras.Name#</a> - #DollarFormat(Extras.Price )#
                  </td>
                  </tr>
                  </cfoutput>
                  </table>

                  --

                  Azadi Saryev
                  Sabai-dee.com
                  http://www.sabai-dee.com
                  • 6. Re: Populating dynamic checkboxes
                    WadeHammer Level 1
                    Thank you Azadi! It works like a charm. Looks simple when I see it now.
                    • 7. Re: Populating dynamic checkboxes
                      Level 7
                      happy to help!
                      --

                      Azadi Saryev
                      Sabai-dee.com
                      http://www.sabai-dee.com