I am not very familiar with javascript so I am piecing this together based on what I can find doing google searches.
I need to get the total of an input value multiplied by a specific number for the fields that are above one another in the code below. This is working fine. I then need to get the sum of all of the totals in to one field. I hope that makes sense. I have tried about ten different ways of doing this with no luck. The code below shows my most recent attempt.
Any help would be greatly appreciated.
Thanks for taking a look.
I need to get the total of an input value multiplied by a specific number for the fields that are above one another in the code below. This is working fine. I then need to get the sum of all of the totals in to one field. I hope that makes sense. I have tried about ten different ways of doing this with no luck. The code below shows my most recent attempt.
Any help would be greatly appreciated.
Code:
<Head>
<script type="text/javascript">
function onlyNumbers(e)
{
var keynum;
var keychar;
var numcheck;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
if(keynum==8) { 'if key is backspace
return true;'allow it
}
keychar = String.fromCharCode(keynum);
numcheck = /\d/;
return numcheck.test(keychar);
}
function updatesum() {
amt5 = document.getElementById('text1').value=(parseFloat(this.value)*5);
amt10 = document.getElementById('text3').value=(parseFloat(this.value)*10);
amt20 = document.getElementById('text5').value=(parseFloat(this.value)*20);
amt25 = document.getElementById('text7').value=(parseFloat(this.value)*25);
amt50 = document.getElementById('text9').value=(parseFloat(this.value)*50);
amt100 = document.getElementById('text11').value=(parseFloat(this.value)*100);
document.CCGCform.total.value = (amt5 * 1) + (amt10 * 1) + (amt20 * 1) + (amt25 * 1) + (amt50 * 1) + (amt100 * 1);
}
</script>
</head>
<body>
<table border="1" width="100%" >
<tr>
<td align="center"> </td>
</tr>
<tr>
<td align="center" valign="top" width="13%">
<Form name="CCGCform" method="Post" action="ccgc.asp" >
<table border="1" width="77%" >
<tr>
<td width="11%" align="center" bgcolor="#F0FFFF"><b>$5.00</b></td>
<td width="11%" align="center" bgcolor="#F5F5F5"><b>$10.00</b></td>
<td width="11%" align="center" bgcolor="#F5FFEC"><b>$20.00</b></td>
<td width="11%" align="center" bgcolor="#F5FFEC"><b>$25.00</b></td>
<td width="11%" align="center" bgcolor="#FFFCE6"><b>$50.00</b></td>
<td width="11%" align="center" bgcolor="#F0F1FF"><b>$100.00</b></td>
<td width="11%" align="center" bgcolor="#F0F1FF" rowspan="2"> </td>
</tr>
<tr>
<td width="11%" align="center" bgcolor="#F0FFFF"><input type="text" name="amt5" size="5" id="text1" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text2').value=(parseFloat(this.value)*5);"></td>
<td width="11%" align="center" bgcolor="#F5F5F5"><input type="text" name="amt10" size="5" id="text3" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text4').value=(parseFloat(this.value)*10);"></td>
<td width="11%" align="center" bgcolor="#F5FFEC"><input type="text" name="amt20" size="5" id="text5" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text6').value=(parseFloat(this.value)*20);"></td>
<td width="11%" align="center" bgcolor="#F5FFEC"><input type="text" name="amt25" size="5" id="text7" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text8').value=(parseFloat(this.value)*25);"></td>
<td width="11%" align="center" bgcolor="#FFFCE6"><input type="text" name="amt50" size="5" id="text9" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text10').value=(parseFloat(this.value)*50);"></td>
<td width="11%" align="center" bgcolor="#F0F1FF"><input type="text" name="amt100" size="5" id="text11" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text12').value=(parseFloat(this.value)*100);"></td>
</tr>
<tr>
<td width="11%" align="center" bgcolor="#F0FFFF"><input type="text" name="amt5total" size="5" id="text2" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text1').value=(parseFloat(this.value)/5);"></td>
<td width="11%" align="center" bgcolor="#F5F5F5"><input type="text" name="amt10total" size="5" id="text4" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text3').value=(parseFloat(this.value)/10);"></td>
<td width="11%" align="center" bgcolor="#F5FFEC"><input type="text" name="amt20total" size="5" id="text6" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text5').value=(parseFloat(this.value)/20);"></td>
<td width="11%" align="center" bgcolor="#F5FFEC"><input type="text" name="amt25total" size="5" id="text8" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text7').value=(parseFloat(this.value)/25);"></td>
<td width="11%" align="center" bgcolor="#FFFCE6"><input type="text" name="amt50total" size="5" id="text10" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text9').value=(parseFloat(this.value)/50);"></td>
<td width="11%" align="center" bgcolor="#F0F1FF"><input type="text" name="amt100total" size="5" id="text12" onkeydown="return onlyNumbers(event)" onkeyup="document.getElementById('text11').value=(parseFloat(this.value)/100);"></td>
<td width="11%" align="center" ><input type=text name="total" size="5"><br><input type=button name=add value=calculate onClick="updatesum()">
</tr>
</table>
</FORM>
Thanks for taking a look.