Solved

Simple Calculation?

Posted on 2001-06-22
2
128 Views
Last Modified: 2010-04-07
How can I have say 10 fields on my web page in which the user inputs some numbers and then a field at the bottom adds them all together?

So simple???!?!?
0
Comment
Question by:JGWY
2 Comments
 
LVL 7

Accepted Solution

by:
daniel_c earned 50 total points
Comment Utility
Is this what you want? Just a simple example:

<html>
<head>
<script language=Javascript>
     function addValue(sVal)
     {
          var iTotal;
          if (!isNaN(sVal)) {
               iTotal = parseInt(document.form1.txtTotal.value);
               iTotal += parseInt(sVal);                    
          }
          else {
               iTotal = parseInt(document.form1.txtTotal.value);
          }
          document.form1.txtTotal.value = iTotal;
          //alert(document.form1.txtTotal.value);
     }
</script>
</head>
<body>
<form name=form1>
Number 01: <input type=text name=txtNumber01 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 02: <input type=text name=txtNumber02 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 03: <input type=text name=txtNumber03 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 04: <input type=text name=txtNumber04 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 05: <input type=text name=txtNumber05 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 06: <input type=text name=txtNumber06 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 07: <input type=text name=txtNumber07 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 08: <input type=text name=txtNumber08 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 09: <input type=text name=txtNumber09 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
Number 10: <input type=text name=txtNumber10 size=3 maxlength=3 onBlur="addValue(this.value)" value="0"><br>
<hr size=1>
Total    : <input type=text name=txtTotal size=3 maxlength=3 value="0">
</form>
</body>
</html>


Hope this helps!

^_^
0
 

Author Comment

by:JGWY
Comment Utility
Spot on, may come back to you for variations on this if I need to. Cheers
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When setting up new project requests for our site, one of the most powerful tools our team has available to use is Axure (http://www.axure.com/). It’s a tool for creating software and web prototypes that can function and interact as if it were the a…
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now