[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I have form fields that I want to populate automatically when I insert a values into other fields. How can I code this?

Posted on 2009-04-20
2
Medium Priority
?
145 Views
Last Modified: 2013-12-24
I have 6 input fields called "charges" and a result input field called "total charges". I want the sum of the 6 input fields to auto sum the total charges field. My current code has not been successful. Where is the problem in my code?
var charges1:Number = 0;
var charges2:Number = 0;
var charges3:Number = 0;
var charges4:Number = 0;
var charges5:Number = 0;
var charges6:Number = 0;
var totalCharges:Number = charges1 + charges2 + charges3 + charges4 + charges5 + charges6;
 
c1.text = charges1.toString();
c2.text = charges2.toString();
c3.text = charges3.toString();
c4.text = charges4.toString();
c5.text = charges5.toString();
c6.text = charges6.toString();
 
c1.addEventListener(KeyboardEvent.KEY_UP, calculate);
c2.addEventListener(KeyboardEvent.KEY_UP, calculate);
c3.addEventListener(KeyboardEvent.KEY_UP, calculate);
c4.addEventListener(KeyboardEvent.KEY_UP, calculate);
c5.addEventListener(KeyboardEvent.KEY_UP, calculate);
c6.addEventListener(KeyboardEvent.KEY_UP, calculate);
 
 
function calculate(event:KeyboardEvent):void
{
	
	charges1.toString() = c1.text;
	charges2.toString() = c2.text;
	charges3.toString() = c3.text;
	charges4.toString() = c4.text;
	charges5.toString() = c5.text;
	charges6.toString() = c6.text;
	c7.text = totalCharges.toString();
}

Open in new window

0
Comment
Question by:rarid122481
2 Comments
 
LVL 37

Accepted Solution

by:
CyanBlue earned 2000 total points
ID: 24189705
I'd do something like this...

CyanBlue
var charges1:Number = 0;
var charges2:Number = 0;
var charges3:Number = 0;
var charges4:Number = 0;
var charges5:Number = 0;
var charges6:Number = 0;
var totalCharges:Number;
 
c1.text = charges1.toString();
c2.text = charges2.toString();
c3.text = charges3.toString();
c4.text = charges4.toString();
c5.text = charges5.toString();
c6.text = charges6.toString();
 
calculate(null);
 
c1.addEventListener(KeyboardEvent.KEY_UP, calculate);
c2.addEventListener(KeyboardEvent.KEY_UP, calculate);
c3.addEventListener(KeyboardEvent.KEY_UP, calculate);
c4.addEventListener(KeyboardEvent.KEY_UP, calculate);
c5.addEventListener(KeyboardEvent.KEY_UP, calculate);
c6.addEventListener(KeyboardEvent.KEY_UP, calculate);
 
 
function calculate(event:KeyboardEvent = null):void
{
        charges1 = parseInt(c1.text);
        charges2 = parseInt(c2.text);
        charges3 = parseInt(c3.text);
        charges4 = parseInt(c4.text);
        charges5 = parseInt(c5.text);
        charges6 = parseInt(c6.text);
        totalCharges = charges1 + charges2 + charges3 + charges4 + charges5 + charges6;
        c7.text = totalCharges.toString();
}

Open in new window

0
 

Author Comment

by:rarid122481
ID: 24189761
perfect
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month18 days, 13 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question