
September 7th, 2004, 11:03 AM
|
|
Web Developer
|
|
Join Date: Feb 2004
Posts: 58
Time spent in forums: 3 h 1 m 4 sec
Reputation Power: 6
|
|
As far as I can tell looking at your code, you are trying to use Javascript (a client based language) with ColdFusion (server based language. You have to convert your CF query to some JS variable or use wddx and then perform calculation on that array.
Quote: | Originally Posted by sangai Hi,
Need help on dynamic calculation using javascript in cfm file. First time added (field1), return correct value, but when change the value (same field eg field1), get wrong total. It suppose not to add the 'new' value and total together. And it can't minus the 'old' value (After correction). What I want is the coding can minus the 'old' value before adding 'new' value to 'total'.
For example:
Code:
<script language="javascript">
function AddTotal(t,no,value){
<cfquery name="get_group" datasource="#pppk#">
select * from pf_acc_group
where grp_code like 'EG%' and l_evel = '3'
</cfquery>
<cfquery name="get_acc" datasource="#pppk#">
select * from pf_accmaster
where acc_no like 'EG%' and grp_rec = '#get_group.rec_no#'
</cfquery>
<cfset last = #get_acc.recordcount#>
var i = document.forms[0].field.value;
<cfoutput>
Total_amount = no.value;
if(Total_amount =="")
Total_amount = 0;
//document.write(document.budget2.subtotal1.value);
var add_amount = t.value;
if(add_amount == "")
add_amount = 0;
Total_amount = Total_amount.toString().replace(',','');
add_amount = add_amount.toString().replace(',','');
//document.write(document.budget2.amount51.value);
Total_amount = parseFloat(Total_amount) + parseFloat(add_amount);
no.value = Total_amount.toString();
</cfoutput>
}
function deduct(t,no,value){
var i = document.forms[0].field.value;
<cfoutput>
var Total_amount;
if(Total_amount =="")
Total_amount = 0;
//document.write(document.budget2.subtotal1.value);
var add_amount = t.value;
if(add_amount == "")
add_amount = 0;
Total_amount = Total_amount.toString().replace(',','');
add_amount = add_amount.toString().replace(',','');
//document.write(document.budget2.amount51.value);
Total_amount = parseFloat(Total_amount) - parseFloat(value);
no.value = Total_amount.toString();
</cfoutput>
}
</script>
 Hope somebody can help. Thanks a lot. |
|