?
Solved

Simple Calculation?

Posted on 2001-06-22
2
Medium Priority
?
136 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 7

Accepted Solution

by:
daniel_c earned 200 total points
ID: 6219098
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
ID: 6219385
Spot on, may come back to you for variations on this if I need to. Cheers
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
Suggested Courses

770 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