Solved

Simple Calculation?

Posted on 2001-06-22
2
129 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
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 Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…

896 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

13 Experts available now in Live!

Get 1:1 Help Now