Skip to main content
January 21, 2007
Question

Delete Loop with ListGetAt

  • January 21, 2007
  • 4 replies
  • 885 views
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?
This topic has been closed for replies.

4 replies

BKBK
Community Expert
Community Expert
January 23, 2007
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#'

BKBK
Community Expert
Community Expert
January 22, 2007
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.

January 22, 2007
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?
BKBK
Community Expert
Community Expert
January 21, 2007
It is apparently unnecessary to end the value of ProductGroupStateID with & "|"
January 22, 2007
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?
January 22, 2007
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.
BKBK
Community Expert
Community Expert
January 21, 2007
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