0

我需要计算发票的总额。此发票是使用表单、金额、数量和税款字段创建的,这些字段的总和是通过 cfinput 中的绑定生成的。我无法计算所有行的总和,即总数。我尝试了一些操作,但没有得出解决方案

这是一个示例代码:

<cfform action="" method="post">
<cfloop from="1" to="3" index="i">

    Q.ta <cfinput type="text" name="quantita#i#" value="0"> 
    + 
    Importo <cfinput type="text" name="importo#i#" value="0"> 
    +
    Tax <cfinput type="text" name="iva#i#" value="0"> 
    = 
    Totale <cfinput type="text" name="totale#i#" value="0" bind="cfc:somma.getSomma({quantita#i#},{importo#i#},{iva#i#})">

    <br /><br />        

</cfloop>

氟氯化碳:

<cfcomponent>
 <cffunction name="getSomma" access="remote" returntype="string">

    <cfargument name="quantita" default="0">
    <cfargument name="importo" default="0">
    <cfargument name="iva" default="0">

    <cfset totaleSomma=#evaluate((importo*quantita)*(1+iva))#>

    <cfreturn totaleSomma>
 </cffunction>  
</cfcomponent>
4

2 回答 2

1

如果您想遍历所有这些表单字段并获得“总计”,我认为您将需要创建一个 Javascript 函数。我的建议是放弃 cfform 并使用 jQuery 创建可编辑的网格。

于 2012-06-13T18:19:32.110 回答
0

好的,我找到了解决方案,我将 cfdiv 用于总计:

<cfparam name="var_tot" default="0">

<cfloop from="1" to="3" index="i">
<cfparam name="totale#i#" default="0">
<cfset var_tot = listappend(var_tot, "{totale"&#i#&"}")>
</cfloop>



<cfform action="" method="post">
<table>
<cfloop from="1" to="3" index="i">
<tr>    
    <td>Q.ta</td><td><cfinput type="text" name="quantita#i#" value="0"></td>  
    <td>Importo</td><td><cfinput type="text" name="importo#i#" value="0"> </td>
    <td>Tax</td><td><cfinput type="text" name="iva#i#" value="0"> </td>
    <td>Totale</td><td class="price"><cfinput type="text" name="totale#i#" value="0" bind="cfc:somma.getSomma({quantita#i#},{importo#i#},{iva#i#})" ></td>      
</tr>
</cfloop>
</table>
</cfform>

<cfdiv bind="url:divtot.cfm?InputText=#var_tot#" id="checktot">

divtot.cfm

<cfparam name="tot" default="0">
<cfset listval=url.InputText>

<cfloop index="i" list="#listval#" delimiters=",">
<cfset tot=tot+i>
</cfloop>


TOTALE: <cfoutput>#tot#</cfoutput>

谢谢大家

于 2012-06-18T16:16:52.690 回答