when there is only a single 0 in one of the array spots and all the other array spots are empty
>> select max(Transaction_ID)as TransactionID
<cfquery result="insertResult" ....>
INSERT INTO Source_Of_Fund_Transaction ....
</cfquery>
<cfset theNewID = insertResult.GENERATEDKEY>
2. I think the user would rather not have to enter a comma when entering the number
...
<cfset AmountUseArr = ListtoArray(form.AmountList)>
<cfif structKeyExists(FORM, "FYList")>
<cfset FundingYearArr = ListToArray(form.FYList)>
<cfset AmountUseArr = ListtoArray(form.AmountList)>
DEBUG: Notice the total elements do NOT match
<cfdump var="#FundingYearArr#">
<cfdump var="#AmountUseArr#">
</cfif>
<form method="post">
Year 1 <input type="text" name="FYList" value="2015">
Amount <input type="text" name="amountList" value="0"><br>
Year 2 <input type="text" name="FYList" value="2016">
Amount 2 <input type="text" name="amountList" value="100"><br>
Year 3 <input type="text" name="FYList" value="2017">
Amount <input type="text" name="amountList" value=""><br>
Year 4 <input type="text" name="FYList" value="2018">
Amount 4 <input type="text" name="amountList" value="95"><br>
<input type="submit">
</form>
<!---- Simulate Action Page ---->
<cfif structKeyExists(FORM, "yearList")>
<!--- Extract amounts for each year --->
<cfloop list="#FORM.yearList#" index="yearNum">
<cfset amount = FORM["amount"& yearNum]>
<cfoutput>
DEBUG: Now processing Year #yearNum# / Amount = #amount#<br>
</cfoutput>
<cfif isNumeric(Amount)>
<!--- do something here --->
</cfif>
</cfloop>
</cfif>
<!----
Simulate Dynamic Form
Use year number as a suffix to relate "Amount" fields.
(Same concept would work if adding fields via javascript)
--->
<cfset yearsToDisplay = [2015,2016,2017,2018]>
<form method="post">
<cfloop array="#yearsToDisplay#" index="yearNum">
<cfoutput>
Year #yearNum#
<!--- Use year as a suffix to relate "Amount" fields. --->
Amount <input type="text" name="amount#yearNum#" value=""><br>
<!--- Use same name for "year" fields, so values are submitted as CSV list --->
<input type="hidden" name="yearList" value="#yearNum#">
</cfoutput>
</cfloop>
<input type="submit">
</form>
3. The form that the user is inserting the dollar figures into puts 0s in the text boxes I think so that it can call a javascript that adds the figures up as the user keys the entry so...
By default, list functions ignore empty elements. CF9+ added the ability to preserve them.
....
B). Use listToArray(list, delim, includeEmptyFields=true):
<cfscript>
result = [];
listEach(form.getselection, function(value, index) {
switch (value) {
case "-2":
result.append(listLast(ListGetAt(form.get_items, index), "~"));
break;
case "-1":
result.append(ListGetAt(getselectiontext, index,',',true));
break;
default:
result.append(value);
}
});
</cfscript>
Insert into Source_Of_Fund_Transaction
(Project_ID,PSC_No,SOF_ID,Current_Allocation,
Current_Contract,Current_Expenditure,Transaction_Type, Transaction_Descn,
Created_By,Creation_Date,Modified_By,Modified_Date)
values (#client.Project_ID#,'#client.PSC_No##FundingYearArr[i]#',#SOFIDArr[i]#,
0,#AmountUse#,0,'C/O Posting','#CONumber#','#client.UserID#',current_timeStamp,'#client.UserID#',current_TimeStamp)
You can always do the check for the user entry if isNUmeric() then put wharever value the client provided otherwise insert 0 into your array,
If from SQL just do isNULL(amount,0) as amount that will make sure no empty field is inserted, and the array will insert blanks so your indexing will be correct
Hope that explains