[thelist] Form & Grand Total

Jay Turley jay at weberrific.org
Fri Oct 20 12:16:14 CDT 2000


> -----Original Message-----
> From: Mona_Nisoff at bd.com [mailto:Mona_Nisoff at bd.com]
> 
> Does anyone have or know where I can l get a javascript that 
> will add the values
> a user enters into 12 separate input fields to ultimately 
> come up with the grand
> total
> of those values? 

Here ya go:

<html>
<head>
	<title>Untitled</title>
  <script language="javascript" type="text/javascript">
  <!--
  function addVals() {
    form = document.myForm;
    var total = 0;
    for (i=1; i<=12; i++) {
      var inputVal = eval("form.value"+i+".value");
      total += parseInt(inputVal);
    }
    form.grandTotal.value = total;
  }
  // -->
  </script>
</head>

<body>
<form name="myForm">
  <input name="value1" type="text" value="0"><br>
  <input name="value2" type="text" value="0"><br>
  <input name="value3" type="text" value="0"><br>
  <input name="value4" type="text" value="0"><br>
  <input name="value5" type="text" value="0"><br>
  <input name="value6" type="text" value="0"><br>
  <input name="value7" type="text" value="0"><br>
  <input name="value8" type="text" value="0"><br>
  <input name="value9" type="text" value="0"><br>
  <input name="value10" type="text" value="0"><br>
  <input name="value11" type="text" value="0"><br>
  <input name="value12" type="text" value="0"><br>
  <input type="button" value="click to add values" onClick="addVals()"><br>
  <input name="grandTotal" type="text" value="">
</form>

</body>
</html>

- Jay Turley ---------------------------------------------------------
  http://www.weberrific.org
 "Any sufficiently advanced magic is indistinguishable from technology"




More information about the thelist mailing list