http://coldfusion.com logo
#cfml-beginners
Title
# cfml-beginners
e

epipko

09/21/2022, 11:13 PM
I have a question about processing data for lines where checkbox is checked. When I hit "Submit", I need to end up with 5 lines in a table. Here is the data in a screenshot. Checkbox''s values is unique.
Copy code
<CFLOOP  query = "ship_details">
				<tr bgcolor="#IIf(CurrentRow Mod 2, DE('ffffff'), DE('f8f8f8'))#">
					<TD class="TDC" align="right"><INPUT TYPE="CHECKBOX" name="MYCHECKBOX" value="#ship_details.cust_po_nbr#" ID="chkPo" checked></TD>
					<TD class="TDC">#ship_details.cust_po_nbr#</TD>
					<TD class="TDC">#ship_details.store_id#</TD>
					<TD class="TDC">#ship_details.numb_of_cart#</TD>
					<TD class="TDC">#ship_details.total_qty#</TD>
					<TD class="TDC">#ship_details.weight#</TD>
					<TD class="TDC">#ship_details.volume#</TD>
					<cfif form.soldto EQ "AMAZON">
						<TD class="TDC"><cfinput name="pallets" type="text" size="10"></TD>
					</cfif>			
				</TR>
			</CFLOOP>
When I try to do streight insert into a table, I am getting an error (too many values) because value for "pallets" comes across as "1,1,3,4,6" How do I loop over checked lines?
m

Michael Schmidt

09/22/2022, 1:01 PM
Like Select Elements Checkboxes by default in ColdFusion when multiple ones come in they are stored as a comma separated list So you will have to loop over that list to insert each value.
e

epipko

09/22/2022, 3:15 PM
Thanks, I already see that. The questions I asked was: How do I loop over checked lines?
m

Michael Schmidt

09/22/2022, 3:28 PM
In your Application.cfc i would have this setting .. this.sameformfieldsasarray=true; then i would have an hidden input next to the pallets input called cust_po_nbr then i would find the checkboxes that are checked with MYCHECKBOX get the cust_po_nbr find the position in the array of the pallet and process that pallet...
i would work with array rather then lists just because the risk of a text entry area to have a comma in it...
e

epipko

09/22/2022, 4:17 PM
Where in Applicaton.cfc I would place this setting?
m

Michael Schmidt

09/22/2022, 4:57 PM
outside of all the functions
e

Evil Ware

09/22/2022, 5:47 PM
Assign a hidden value, like ID, to each row, then on your input query, you can loop over the ID and insert a reference for the index.
Copy code
cfloop from="1" to="100" index="i">
    <cfif ((i MOD 100) EQ 1)>
    INSERT INTO MyTable
    (
    [MycolName]
    )
    VALUES
    </cfif>
    (
        '#i#'
    )
    <cfif (i LT 999)><cfif ((i MOD 100) NEQ 0)>,</cfif>#CHR(13)##CHR(10)#</cfif>
</cfloop></cfquery>