ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 3rd, 2004, 03:18 AM
sangai sangai is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 2 sangai User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Exclamation Dynamic Calculation

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.

Reply With Quote
  #2  
Old September 7th, 2004, 11:03 AM
kaasu kaasu is offline
Web Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 58 kaasu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Dynamic Calculation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT