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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 141
  • Last Modified:

Simple Calculation?

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
JGWY
Asked:
JGWY
1 Solution
 
daniel_cCommented:
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
 
JGWYAuthor Commented:
Spot on, may come back to you for variations on this if I need to. Cheers
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now