• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Delete Loop with ListGetAt

Participant ,
Jan 21, 2007 Jan 21, 2007

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

663

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2007 Jan 21, 2007

Copy link to clipboard

Copied

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


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 21, 2007 Jan 21, 2007

Copy link to clipboard

Copied

It is apparently unnecessary to end the value of ProductGroupStateID with & "|"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 21, 2007 Jan 21, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 21, 2007 Jan 21, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

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..

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

Frack.. double post

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 22, 2007 Jan 22, 2007

Copy link to clipboard

Copied

LATEST
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#'

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation