2012-06-13 46 views
0

我需要计算发票的总数。此发票是使用表单,金额,数量和税收字段创建的,这些字段的总和是使用cfinput中的绑定进行的。 我不能使所有行的总和,总和。 我尝试了一些行动,但在解决总结表单中绑定的字段,从cfc

没有抵达,这是一个例子代码:

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

CFC:

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

回答

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> 

谢谢大家

1

我想你需要创建一个Javascript函数,如果你想循环所有这些形式feilds并获得“总计”。我的建议是放弃cfform并使用jQuery创建一个可编辑的网格。

+1

我都赞成下降的使用jQuery验证器。还没回头... –