9 Replies Latest reply on Jan 22, 2007 9:08 PM by BKBK

    Delete Loop with ListGetAt

    mikeap Level 1
      I have a hidden form field with a combined value. On check I want to delete from my db. The problem is it's only deleting one record, the first checkbox selected and no others. What am I doing wrong?
        • 1. Re: Delete Loop with ListGetAt
          BKBK Adobe Community Professional & MVP
          Check 2 or 3 boxes in the following snippet, and you should see what the matter is with your code.

          <cfif isdefined("form.sbmt")>
          <cfdump var="#form#">
          </cfif>
          <cfoutput><form action="#cgi.script_name#" method="post"></cfoutput>
          <p>
          <input type="checkbox" name="ProductGroupID" value="box1">chkbx1<br>
          <input type="checkbox" name="ProductGroupID" value="box2">chkbx2<br>
          <input type="checkbox" name="ProductGroupID" value="box3">chkbx3<br>
          </p>
          <input type="submit" value="submit" name="sbmt">
          </form>

          The checkboxes share the same name. Hence there will only be one value of form.ProductGroupID, irrespective of the number of boxes that you check. If you check more than one box, form.ProductGroupID will store the respective values as a comma-delimited list.

          I would suggest that you differentiate the names of the boxes dynamically, as follows


          • 2. Re: Delete Loop with ListGetAt
            BKBK Adobe Community Professional & MVP
            It is apparently unnecessary to end the value of ProductGroupStateID with & "|"
            • 3. Re: Delete Loop with ListGetAt
              mikeap Level 1
              Okay, I think I've done that here ... but now I'm getting a new error that I do not have a 2, 3 or 4 element in my list on my action page.

              Do you see what I'm doing wrong?
              • 4. Re: Delete Loop with ListGetAt
                mikeap Level 1
                I don't understand why it only contains one element, it should find all four right?

                Variables.ProductGroupStateID = "Form.ProductGroupID" & #delProductGroupState#

                should produce a value of "9756|IEE|T-07|AL" or "9756|Workholding|T-07|MI"

                I'm really trying ... I could just be dumb.
                • 5. Re: Delete Loop with ListGetAt
                  BKBK Adobe Community Professional & MVP
                  I don't understand why it only contains one element, it should find all four right?
                  Wrong. Do the test I gave you, and see for yourself. If four checkboxes share the same name x, there will just be one value of form.x.

                  • 6. Re: Delete Loop with ListGetAt
                    mikeap Level 1
                    Each checkbox has its own name as you can see in the attached code. it produces names as the following:

                    ProductGroupID1
                    ProductGroupID2
                    ProductGroupID3

                    so the name and the value is not the problem anymore? is it something on my action page?
                    • 7. Re: Delete Loop with ListGetAt
                      mvierow Level 1
                      Posted form vars with the same name will be comma delimited. If you are nesting lists, then you need to pass the location of your outter loop to the listGetAt function.

                      From your original code..
                      #ListGetAt(listGetAt(Form.ProductGroupID,delProductGroupState), 1, "|")#

                      I really recommend not nesting the lists.. it's not helping you that much, and it puts your application at risk by giving the end user to much control over the data. Try just passing the ID number - whichever one is most relavant - then using an insert statement in combination with a select statement to get whatever info you need during the insert. This way you don't need to worry about your string data possibly containing one of the delimiters and ruining everything on you.

                      Something like this..
                      INSERT INTO table (field1,field2,field3,field4)
                      (SELECT 'some text' as field1, tablename.field2, othertable.field3, 'string' as field4 FROM etc..... )

                      You can replace the literal strings "some text" or "string" with form vars to allow for data to be inserted from the form scope and from the select query at the same time..
                      • 8. Delete Loop with ListGetAt
                        mvierow Level 1
                        Frack.. double post
                        • 9. Re: Delete Loop with ListGetAt
                          BKBK Adobe Community Professional & MVP
                          Each checkbox has its own name as you can see in the attached code. it produces names as the following:
                          ProductGroupID1
                          ProductGroupID2
                          ProductGroupID3
                          so the name and the value is not the problem anymore? is it something on my action page?


                          No, uncorrected old cold still appears here and there. For example, in the line
                          <cfif Evaluate(Variables.ProductGroupID) NEQ "">

                          I would replace the lines

                          <cfset Variables.ProductGroupStateID = "Form.ProductGroupID" & #delProductGroupState#>
                          <cfif Evaluate(Variables.ProductGroupID) NEQ "">
                          WHERE Distributor_ID = #Evaluate(Variables.Distributor_ID)#
                          AND Product_Category = '#Evaluate(Variables.Product_Category)#'
                          AND Username = '#Evaluate(Variables.Username)#'
                          AND Authorized_State = '#Evaluate(Variables.Authorized_State)#'


                          respectively, with the lines

                          <cfset Variables.ProductGroupID = #Evaluate(Form.ProductGroupID & delProductGroupState)#>
                          <cfif Variables.ProductGroupID NEQ "">
                          WHERE Distributor_ID = #Variables.Distributor_ID#
                          AND Product_Category = '#Variables.Product_Category#'
                          AND Username = '#Variables.Username#'
                          AND Authorized_State = '#Variables.Authorized_State#'