Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2006, 09:20 PM
Registered User
 
Join Date: Jul 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Calculating input values with arrays

I would like to have someone to help me out with my program.Users are able to add items if they wish for the Monthly Claims Charges System.I did not manage to do the calculation part of the program.Could someone help me?Here is the program:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
    <title>Monthly claims Charges</title>
    <script language="javascript">


    function dosum()
    {
    var i = 0;
    while(i < document.temps.item1.length){
    document.temps.total1.value += parseFloat(document.temps.item1[i].value);
    window.alert("The number entered is: " + document.temps.item1[i].value);
    return parseFloat(document.temps.total1.value);
    i++;}
    }



var nextSubject = new Array(100) ;
var counter = 1 ;

function addRow(){
 var tbody = document.getElementById("table1").getElementsByTag Name("tbody")[0];
 if (!tbody.crow){
  var rows=tbody.getElementsByTagName('TR');
  tbody.crow=rows[rows.length-1];
 }
 var nrow=tbody.crow.cloneNode(true);
 var eles=nrow.getElementsByTagName('*');
 for (var zxc0=0;zxc0<eles.length;zxc0++){
  if (eles[zxc0].name){ eles[zxc0].name=eles[zxc0].name.replace('0',counter); }
  if (eles[zxc0].id){ eles[zxc0].id=eles[zxc0].id.replace('0',counter); }
  if (eles[zxc0].tagName=='INPUT'){ eles[zxc0].value=''+eles[zxc0].value; } // change to eles[zxc0].value='' when ready
  if (eles[zxc0].tagName=='SELECT'){ eles[zxc0].selectedIndex=0; }
 }
 counter++;
 tbody.appendChild(nrow);
}



var nextSubjectA = new Array(100) ;
var counterA = 1 ;

function addRowA(){
 var tbody = document.getElementById("table2").getElementsByTag Name("tbody")[0];
 if (!tbody.crow){
  var rows=tbody.getElementsByTagName('TR');
  tbody.crow=rows[rows.length-1];
 }
 var nrow=tbody.crow.cloneNode(true);
 var eles=nrow.getElementsByTagName('*');
 for (var zxc0=0;zxc0<eles.length;zxc0++){
  if (eles[zxc0].name){ eles[zxc0].name=eles[zxc0].name.replace('0',counterA); }
  if (eles[zxc0].id){ eles[zxc0].id=eles[zxc0].id.replace('0',counterA); }
  if (eles[zxc0].tagName=='INPUT'){ eles[zxc0].value=''+eles[zxc0].name; } // change to eles[zxc0].value='' when ready
  if (eles[zxc0].tagName=='SELECT'){ eles[zxc0].selectedIndex=0; }
 }
 counterA++;
 tbody.appendChild(nrow);
}

</script>

</head>

<body>

<form NAME="temps">
<P align=center><STRONG>YTL E-SOLUTIONS BERHAD- Monthly claim
Charges</STRONG></P>
<P align=center>MONTH: __________________</P>
<P align=center>NAME:________________________________ __________</P>
<table border="0" align="center" width = "80%" id="table1" bgcolor="#99cc99">
<tr>
    <td><STRONG>ITEMS</STRONG></td>
    <td>
      <P align=left><STRONG>PAGE REF.</STRONG></P></td>
    <td>
      <P align=center><STRONG>&nbsp;RM</STRONG></P></td>
</tr>
<tr >
    <td><STRONG>1) PETROL,PARKING
      &amp; TRAVELLING&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;</STRONG></td>
    <td></td>
    <td></td>
</tr>
<tr>
    <td>Petrol / Mileage Claims</td>
    <td><INPUT maxLength=10 size=10>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td>
      <P align=right><INPUT maxLength=10 size=10 name="item1" onChange="dosum()" value="0"></P></td>
</tr>
<tr>
    <td>Parking, Toll and Touch &amp; Go (Top Up)</td>
    <td><INPUT maxLength=10 size=10></td>
    <td>
      <P align=right><INPUT maxLength=10 size=10 name="item1" onChange="dosum()" value="0"></P></td>
</tr>
<tr>
    <td>Taxi Fare, Air Fare, Bus Fare and etc</td>
    <td><INPUT maxLength=10 size=10></td>
    <td>
      <P align=right><INPUT maxLength=10 size=10 name="item1" onChange="dosum()" value="0"></P></td>
</tr>
<tr>
    <td>
      <INPUT maxLength=30 size=30
      name=" "
      ="32142">
    </td>
    <td><INPUT maxLength=10 size=10
      name=""
      ="32144"></td>
    <td>
      <P align=right><INPUT maxLength=2 size=10
      name="item1" onChange="dosum()" value="0"></P></td>
</tr></table>
<P align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT onclick=addRow(); type=button value="Insert Row">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<TABLE align=center border=0 width = "80%">

  <TR>
    <TD>
      <P
      align=right>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;Total:&nbsp;<INPUT
      maxLength=10 size=10 name ="total1" input></P>


    </TD></TR></TABLE></P>

</form>

</body>
</html>








Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculating Gridview Column Values rit01 ASP.NET 2.0 Professional 1 October 18th, 2006 03:46 PM
calculating values aceconcepts PHP How-To 0 February 16th, 2006 09:01 AM
Calculating Grouped Report Values SteveH Access 1 October 15th, 2005 03:00 PM
Calculating "Sum" of Numeric values in Varchar fld itHighway Classic ASP Basics 6 December 29th, 2004 07:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.